Add files via upload

main
PJ568 2 years ago committed by GitHub
parent de4f07b63e
commit f958ce99c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,2 +1,5 @@
# 568tools
Online Tools
# 568Tools 在线工具箱
568Tools 在线工具箱是在线工具的集合。使用大部分工具无需注册、下载或上传到服务器。
服务涵盖:文件转换、加密解密、站长工具、代码开发、生活相关等。

@ -0,0 +1,27 @@
[
{
"name":"PJ568的博客",
"url":"https://PJ568.eu.org/",
"type":"568服务"
},
{
"name":"568Tools 在线工具箱",
"url":"https://Tools.PJ568.eu.org/",
"type":"568服务"
},
{
"name":"转转雀 - Github 文件加速",
"url":"https://proxy.PJ568.eu.org/",
"type":"568服务"
},
{
"name":"Chat.pj568.eu.org",
"url":"https://Chat.pj568.eu.org/",
"type":"568服务"
},
{
"name":"32 位 x86 虚拟机",
"url":"/tool/v86/",
"type":"软件模拟"
}
]

@ -1,15 +1,43 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>PJ568的工具站</title>
<meta http-equiv="refresh" content="5;url=https://Tools.PJ568.EU.ORG/web_vm">
</head>
<body>
<header>PJ568的工具站</header>
<main>
<h1>临时</h1>
<p>页面将会在几秒内自动跳转。</p>
</main>
</body>
<html>
<head>
<meta charset="utf-8"/>
<meta name="description" content="568Tools 在线工具箱是在线工具的集合。使用大部分工具无需注册、下载或上传到服务器。服务涵盖:文件转换、加密解密、站长工具、代码开发、生活相关等。">
<title>568Tools&nbsp;在线工具箱</title>
<link rel="stylesheet" href="../css/tool_type.css">
</head>
<body>
<div class="bg-img"></div>
<div id="list" class="nav_content">
<!-- 信息栏(初始化) -->
<!-- 工具表(插入) -->
<!-- 后补内容 -->
</div>
<!-- 顶栏 -->
<div class="nav_menu">
<a class="menu_item_href" href="#">568Tools&nbsp;在线工具箱</a>
<p class="menu_item_href">|</p>
<div class="menu_item"><span>分类</span>
<div id="nav" class="menu_child"><!-- nav_html的插入位置包含初始化、插入和后补 --></div>
</div>
<p class="menu_item_href">|</p>
<a class="menu_item_href" href="https://Tools.pj568.eu.org/license">许可证</a>
<a class="menu_item_href" href="https://Tools.pj568.eu.org/comment">留言反馈</a>
<a class="menu_item_href" href="https://Tools.pj568.eu.org/application">提交页面</a>
<div class="search_box"><input class="search_in" id="keyword" maxlength="18" placeholder="请键入关键词">
<div id="searchContent"></div>
<svg t="1626534436665" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4200" width="64" height="64">
<path d="M466.69056 804.488541c-90.212628 0-175.009919-35.130102-238.789525-98.914824-131.605364-131.650389-131.605364-345.864192-0.007163-477.524814 63.785745-63.793932 148.58406-98.920964 238.796688-98.920964 90.214674 0 175.011966 35.128055 238.791571 98.920964 131.612527 131.660622 131.612527 345.874425 0 477.524814C641.702526 769.358439 556.905234 804.488541 466.69056 804.488541zM466.69056 177.066765c-77.399811 0-150.167115 30.142507-204.894553 84.876086-112.910583 112.965841-112.910583 296.77824 0.007163 409.737942 54.720276 54.726415 127.487579 84.866876 204.88739 84.866876 77.403904 0 150.169161-30.139437 204.895577-84.866876 112.919792-112.959701 112.919792-296.772101 0-409.737942C616.859721 207.208249 544.093441 177.066765 466.69056 177.066765z" p-id="4201" fill="#8a8a8a"></path>
<path d="M860.908016 894.871037 726.797599 760.77597 760.691547 726.883045 894.802988 860.976066Z" p-id="4202" fill="#8a8a8a"></path>
</svg>
</div>
<a href="https://github.com/PJ-568/568tools" target="_blank" rel="noopener noreferrer" title="github" class="github">
<svg>
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"></path>
</svg>
</a>
</div>
</body>
</html>
<script src="js/api.js"></script>
<script src="js/popup.js"></script>

@ -0,0 +1,34 @@
var classify = [{
"id": 1,
"name": "568服务",
"list": [{
"name": "PJ568的博客",
"url": "https://PJ568.eu.org/",
"hot": 0,
"img": ""
}, {
"name": "568Tools&nbsp;在线工具箱",
"url": "https://Tools.pj568.eu.org/",
"hot": 1,
"img": ""
}, {
"name": "转转雀&nbsp;-&nbsp;Github&nbsp;文件加速",
"url": "https://proxy.pj568.eu.org/",
"hot": 1,
"img": ""
}, {
"name": "Chat.pj568.eu.org",
"url": "https://chat.pj568.eu.org/",
"hot": 0,
"img": ""
}]
}, {
"id": 2,
"name": "软件模拟",
"list": [{
"name": "32&nbsp;位&nbsp;x86&nbsp;虚拟机",
"url": "/tool/v86/",
"hot": 0,
"img": ""
}]
}]

@ -0,0 +1,154 @@
function getD(val,type){
if(!type){
return document.getElementById(val);
}
if(type='class'){
return document.getElementsByClassName(val);
}
}
function throttle(fn, delay) {
delay=delay || 200;
let timer = null;
return function () {
if(timer) return;
timer = setTimeout(() => {
fn.apply(this,arguments);
timer = null;
})
}
}
function setSotreList(data){
var sotreList=localStorage.getItem('list');
var max=8;
sotreList=JSON.parse(sotreList || '[]');
for(let i in sotreList){
if(sotreList[i].name==data.name){
sotreList.splice(i,1);
}
}
sotreList.splice(max,sotreList.length-max);
sotreList.unshift(data);
localStorage.setItem('list',JSON.stringify(sotreList));
}
var _URL='https://Tools.pj568.eu.org/';
function initData(){
var nav=getD('nav'),
list=getD('list'),
keyword=getD('keyword'),
nav_html='',
list_html='',
sotreList=localStorage.getItem('list');
// 初始化
list_html+=`<div class="item info"><h2>欢迎使用&nbsp;568Tools&nbsp;在线工具箱</h2><div id="ad_line" style="margin: 0 10px;"></div><p>致力于创造并维护无需注册、下载和上传即可免费使用的静态在线工具环境。部分项目来源于开源项目,浅蓝色标记为热门工具。<a href="./data.json" target="_blank">点击查看</a>&nbsp;json&nbsp;数据。</p><p><strong>如果您有问题或建议,请不要吝啬您的<a rel="nofollow" target="_blank" href="./comment">留言反馈</a>,感谢使用及分享!</strong>本站欢迎<a rel="nofollow" target="_blank" href="./comment">提交您的页面</a>,本站将持续更新。</p><p>下载&nbsp;<strong>[568Tools&nbsp;工具箱]</strong>&nbsp;浏览器扩展插件或应用程序以供离线使用:<a rel="nofollow" target="_blank" href="https://chrome.google.com/webstore/detail/fly63%E5%B7%A5%E5%85%B7%E7%AE%B1/oicicpjppdafaknaepojmjpjoinimbel">谷歌 Chrome</a>、<a rel="nofollow" target="_blank" href="https://addons.mozilla.org/zh-CN/firefox/addon/fly63%E5%B7%A5%E5%85%B7%E7%AE%B1/">火狐 Firefox</a>、<a rel="nofollow" target="_blank" href="https://microsoftedge.microsoft.com/addons/detail/akpeonmkmdaifdnliibdoklpjcecdcnk">微软 Edge</a>、<a rel="nofollow" target="_blank" href="/lib/plug/flytool.crx">crx文件下载</a>。</p></div>`
// nav_html+=`<a class="menu_item_href" href="https://Tools.pj568.eu.org/">568Tools&nbsp;在线工具箱</a><a class="menu_item_href">|</a>`
// 初始化结束
if(!!sotreList){
sotreList=JSON.parse(sotreList);
// 最近访问
list_html+=`<div class="item"><h2>最近访问</h2><div class="child">`;
for(var i in sotreList){
var li = sotreList[i];
list_html+=`<a href="${li.url}" target="_self">${li.name}</a>`;
}
list_html+=`</div></div>`;
}
for(var i in classify){
var item=classify[i];
// 顶栏的按钮
nav_html+=`<a href="#${item.id}">${item.name}</a>`;
// 主要选项
list_html+=`<div id="${item.id}" class="item"><h2>${item.name}</h2><div class="child">`;
for(var j in item.list){
var li=item.list[j];
list_html+=`<a href="${li.url}"${li.hot==1 ? ' class="red" ' : ''}idx="${i}_${j}" target="_self" title="${li.name}">${li.name}</a>`;
}
list_html+=`</div></div>`;
}
// 后补
nav_html+=`<a href="#0" target="_self">页内页</a>`
list_html+=`<div id="0" class="item"><h2>页内页</h2><div class="child"><iframe src="https://pj568.eu.org/Spinning_Bird/" class="page"></iframe></div></div><div class="item"><a class="ota" href="#">↑↑&nbsp;&nbsp;&nbsp;&nbsp;返回页顶&nbsp;&nbsp;&nbsp;&nbsp;↑↑</a></div>`
// 后补结束
nav.innerHTML=nav_html;
list.innerHTML=list_html;
getD("classify").addEventListener("click",setClassify);
list.addEventListener("click",function(e){
if(e.target.getAttribute('class').indexOf('sli')>-1){
toHref(e.target);
}
});
keyword.addEventListener('input', throttle(setSearch));
keyword.addEventListener('focus', throttle(setSearch));
keyword.addEventListener('blur', function() {
setTimeout(function() {
getD('searchContent').innerHTML = '';
}, 250)
});
getD('closekeyword').addEventListener("click",function(){
keyword.value='';
this.style.display= 'none';
});
getD('searchContent').addEventListener("click",function(e){
if(e.target.getAttribute('class')=='ssli'){
toHref(e.target);
}
});
getD('logo').addEventListener('click',function(e){
var url=_URL+'/tool/home.html';
window.open(url,'_blank');
});
}
function setSearch(value){
var value=this.value.trim();
var searchContent = getD('searchContent');
var closekeyword = getD('closekeyword');
var shtml = '';
value = value.toLowerCase(); //输入值
if (value == '') {
searchContent.innerHTML = '';
closekeyword.style.display= 'none';
return;
}
closekeyword.style.display= 'block';
for (var i in classify) {
for (var j in classify[i].list) {
var li = classify[i].list[j];
if (!!li.name && li.name.toLowerCase().indexOf(value) > -1) {
shtml += `<a class="ssli" idx="${i}_${j}" class="${li.hot==1 ? 'hot' : ''}" target="_self" title="${li.name}">${li.name}</a>`;
}
}
}
searchContent.innerHTML = shtml;
}
function toHref(dom){
var idx=dom.getAttribute('idx');
var url=dom.getAttribute('url');
if(!!idx){
idx=idx.split('_');
var data=classify[idx[0]].list[idx[1]];
setSotreList(data);
url=data.url;
}
if(!url){
return;
}
if(!(url.indexOf('http://')>-1 || url.indexOf('https://')>-1)){
url=_URL+url;
}
window.open(url,'_blank');
}
function setClassify(){
var cls=getD('cls'),
nav=getD('nav'),
line=getD('line');
var val=cls.getAttribute('class');
if(!val){
cls.setAttribute('class','rotate');
nav.style.display='block';
line.style.height='132px';
return;
}
cls.setAttribute('class','');
line.style.height='44px';
nav.style.display='none';
}
initData();

@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,13 @@
set -e
git clone https://git.seabios.org/seabios.git || true
(cd seabios && git checkout rel-1.12.1)
cp seabios.config seabios/.config
make -C seabios
cp seabios/out/bios.bin seabios.bin
cp seabios/out/vgabios.bin vgabios.bin
cp seabios-debug.config seabios/.config
make -C seabios
cp seabios/out/bios.bin seabios-debug.bin
cp seabios/out/vgabios.bin vgabios-debug.bin

Binary file not shown.

@ -0,0 +1,117 @@
#
# Automatically generated file; DO NOT EDIT.
# SeaBIOS Configuration
#
#
# General Features
#
# CONFIG_COREBOOT is not set
CONFIG_QEMU=y
# CONFIG_CSM is not set
CONFIG_QEMU_HARDWARE=y
CONFIG_XEN=y
CONFIG_THREADS=y
# CONFIG_RELOCATE_INIT is not set
# CONFIG_BOOTMENU is not set
CONFIG_BOOTORDER=y
CONFIG_MULTIBOOT=y
CONFIG_ENTRY_EXTRASTACK=y
CONFIG_MALLOC_UPPERMEMORY=y
CONFIG_ROM_SIZE=0
#
# Hardware support
#
CONFIG_ATA=y
CONFIG_ATA_DMA=y
CONFIG_ATA_PIO32=y
CONFIG_AHCI=y
CONFIG_SDCARD=y
CONFIG_VIRTIO_BLK=y
CONFIG_VIRTIO_SCSI=y
CONFIG_PVSCSI=y
CONFIG_ESP_SCSI=y
CONFIG_LSI_SCSI=y
CONFIG_MEGASAS=y
CONFIG_MPT_SCSI=y
CONFIG_FLOPPY=y
CONFIG_FLASH_FLOPPY=y
# CONFIG_NVME is not set
CONFIG_PS2PORT=y
# CONFIG_USB is not set
CONFIG_SERIAL=y
# CONFIG_SERCON is not set
CONFIG_LPT=y
CONFIG_RTC_TIMER=y
CONFIG_HARDWARE_IRQ=y
CONFIG_USE_SMM=y
CONFIG_CALL32_SMM=y
CONFIG_MTRR_INIT=y
CONFIG_PMTIMER=y
CONFIG_TSC_TIMER=y
#
# BIOS interfaces
#
CONFIG_DRIVES=y
CONFIG_CDROM_BOOT=y
CONFIG_CDROM_EMU=y
CONFIG_PCIBIOS=y
CONFIG_APMBIOS=y
CONFIG_PNPBIOS=y
CONFIG_OPTIONROMS=y
CONFIG_PMM=y
CONFIG_BOOT=y
CONFIG_KEYBOARD=y
CONFIG_KBD_CALL_INT15_4F=y
CONFIG_MOUSE=y
CONFIG_S3_RESUME=y
CONFIG_VGAHOOKS=y
# CONFIG_DISABLE_A20 is not set
# CONFIG_WRITABLE_UPPERMEMORY is not set
CONFIG_TCGBIOS=y
#
# BIOS Tables
#
CONFIG_PIRTABLE=y
CONFIG_MPTABLE=y
# CONFIG_SMBIOS is not set
CONFIG_ACPI=y
CONFIG_ACPI_DSDT=y
CONFIG_FW_ROMFILE_LOAD=y
#
# VGA ROM
#
# CONFIG_NO_VGABIOS is not set
# CONFIG_VGA_STANDARD_VGA is not set
# CONFIG_VGA_CIRRUS is not set
CONFIG_VGA_BOCHS=y
# CONFIG_VGA_GEODEGX2 is not set
# CONFIG_VGA_GEODELX is not set
# CONFIG_DISPLAY_BOCHS is not set
# CONFIG_VGA_RAMFB is not set
CONFIG_VGA_BOCHS_STDVGA=y
# CONFIG_VGA_BOCHS_VMWARE is not set
# CONFIG_VGA_BOCHS_QXL is not set
# CONFIG_VGA_BOCHS_VIRTIO is not set
CONFIG_BUILD_VGABIOS=y
CONFIG_VGA_STDVGA_PORTS=y
CONFIG_VGA_FIXUP_ASM=y
CONFIG_VGA_ALLOCATE_EXTRA_STACK=y
CONFIG_VGA_EXTRA_STACK_SIZE=512
CONFIG_VGA_VBE=y
CONFIG_VGA_PCI=y
CONFIG_OVERRIDE_PCI_ID=y
CONFIG_VGA_VID=0x1234
CONFIG_VGA_DID=0x1111
#
# Debugging
#
CONFIG_DEBUG_LEVEL=8
# CONFIG_DEBUG_SERIAL is not set
# CONFIG_DEBUG_SERIAL_MMIO is not set
CONFIG_DEBUG_IO=y

Binary file not shown.

@ -0,0 +1,114 @@
#
# Automatically generated file; DO NOT EDIT.
# SeaBIOS Configuration
#
#
# General Features
#
# CONFIG_COREBOOT is not set
CONFIG_QEMU=y
# CONFIG_CSM is not set
CONFIG_QEMU_HARDWARE=y
CONFIG_XEN=y
CONFIG_THREADS=y
# CONFIG_RELOCATE_INIT is not set
# CONFIG_BOOTMENU is not set
CONFIG_BOOTORDER=y
CONFIG_MULTIBOOT=y
CONFIG_ENTRY_EXTRASTACK=y
CONFIG_MALLOC_UPPERMEMORY=y
CONFIG_ROM_SIZE=0
#
# Hardware support
#
CONFIG_ATA=y
CONFIG_ATA_DMA=y
CONFIG_ATA_PIO32=y
CONFIG_AHCI=y
CONFIG_SDCARD=y
CONFIG_VIRTIO_BLK=y
CONFIG_VIRTIO_SCSI=y
CONFIG_PVSCSI=y
CONFIG_ESP_SCSI=y
CONFIG_LSI_SCSI=y
CONFIG_MEGASAS=y
CONFIG_MPT_SCSI=y
CONFIG_FLOPPY=y
CONFIG_FLASH_FLOPPY=y
# CONFIG_NVME is not set
CONFIG_PS2PORT=y
# CONFIG_USB is not set
CONFIG_SERIAL=y
# CONFIG_SERCON is not set
CONFIG_LPT=y
CONFIG_RTC_TIMER=y
CONFIG_HARDWARE_IRQ=y
CONFIG_USE_SMM=y
CONFIG_CALL32_SMM=y
CONFIG_MTRR_INIT=y
CONFIG_PMTIMER=y
CONFIG_TSC_TIMER=y
#
# BIOS interfaces
#
CONFIG_DRIVES=y
CONFIG_CDROM_BOOT=y
CONFIG_CDROM_EMU=y
CONFIG_PCIBIOS=y
CONFIG_APMBIOS=y
CONFIG_PNPBIOS=y
CONFIG_OPTIONROMS=y
CONFIG_PMM=y
CONFIG_BOOT=y
CONFIG_KEYBOARD=y
CONFIG_KBD_CALL_INT15_4F=y
CONFIG_MOUSE=y
CONFIG_S3_RESUME=y
CONFIG_VGAHOOKS=y
# CONFIG_DISABLE_A20 is not set
# CONFIG_WRITABLE_UPPERMEMORY is not set
CONFIG_TCGBIOS=y
#
# BIOS Tables
#
CONFIG_PIRTABLE=y
CONFIG_MPTABLE=y
# CONFIG_SMBIOS is not set
CONFIG_ACPI=y
CONFIG_ACPI_DSDT=y
CONFIG_FW_ROMFILE_LOAD=y
#
# VGA ROM
#
# CONFIG_NO_VGABIOS is not set
# CONFIG_VGA_STANDARD_VGA is not set
# CONFIG_VGA_CIRRUS is not set
CONFIG_VGA_BOCHS=y
# CONFIG_VGA_GEODEGX2 is not set
# CONFIG_VGA_GEODELX is not set
# CONFIG_DISPLAY_BOCHS is not set
# CONFIG_VGA_RAMFB is not set
CONFIG_VGA_BOCHS_STDVGA=y
# CONFIG_VGA_BOCHS_VMWARE is not set
# CONFIG_VGA_BOCHS_QXL is not set
# CONFIG_VGA_BOCHS_VIRTIO is not set
CONFIG_BUILD_VGABIOS=y
CONFIG_VGA_STDVGA_PORTS=y
CONFIG_VGA_FIXUP_ASM=y
CONFIG_VGA_ALLOCATE_EXTRA_STACK=y
CONFIG_VGA_EXTRA_STACK_SIZE=512
CONFIG_VGA_VBE=y
CONFIG_VGA_PCI=y
CONFIG_OVERRIDE_PCI_ID=y
CONFIG_VGA_VID=0x1234
CONFIG_VGA_DID=0x1111
#
# Debugging
#
CONFIG_DEBUG_LEVEL=0

Binary file not shown.

Binary file not shown.

@ -0,0 +1,822 @@
;(function(){'use strict';var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};
$jscomp.getGlobal=function(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);$jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};
$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(a,b){var c=$jscomp.propertyToPolyfillSymbol[b];if(null==c)return a[b];c=a[c];return void 0!==c?c:a[b]};$jscomp.polyfill=function(a,b,c,d){b&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(a,b,c,d):$jscomp.polyfillUnisolated(a,b,c,d))};
$jscomp.polyfillUnisolated=function(a,b,c,d){c=$jscomp.global;a=a.split(".");for(d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))return;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:b})};
$jscomp.polyfillIsolated=function(a,b,c,d){var e=a.split(".");a=1===e.length;d=e[0];d=!a&&d in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var g=0;g<e.length-1;g++){var f=e[g];if(!(f in d))return;d=d[f]}e=e[e.length-1];c=$jscomp.IS_SYMBOL_NATIVE&&"es6"===c?d[e]:null;b=b(c);null!=b&&(a?$jscomp.defineProperty($jscomp.polyfills,e,{configurable:!0,writable:!0,value:b}):b!==c&&(void 0===$jscomp.propertyToPolyfillSymbol[e]&&(c=1E9*Math.random()>>>0,$jscomp.propertyToPolyfillSymbol[e]=$jscomp.IS_SYMBOL_NATIVE?
$jscomp.global.Symbol(e):$jscomp.POLYFILL_PREFIX+c+"$"+e),$jscomp.defineProperty(d,$jscomp.propertyToPolyfillSymbol[e],{configurable:!0,writable:!0,value:b})))};$jscomp.polyfill("globalThis",function(a){return a||$jscomp.global},"es_2020","es3");$jscomp.polyfill("String.prototype.trimRight",function(a){function b(){return this.replace(/[\s\xa0]+$/,"")}return a||b},"es_2019","es3");
var LOG_ALL=-1,LOG_NONE=0,LOG_OTHER=1,LOG_CPU=2,LOG_FPU=4,LOG_MEM=8,LOG_DMA=16,LOG_IO=32,LOG_PS2=64,LOG_PIC=128,LOG_VGA=256,LOG_PIT=512,LOG_MOUSE=1024,LOG_PCI=2048,LOG_BIOS=4096,LOG_FLOPPY=8192,LOG_SERIAL=16384,LOG_DISK=32768,LOG_RTC=65536,LOG_HPET=131072,LOG_ACPI=262144,LOG_APIC=524288,LOG_NET=1048576,LOG_VIRTIO=2097152,LOG_9P=4194304,LOG_SB16=8388608,LOG_NAMES=[[1,""],[LOG_CPU,"CPU"],[LOG_DISK,"DISK"],[LOG_FPU,"FPU"],[LOG_MEM,"MEM"],[LOG_DMA,"DMA"],[LOG_IO,"IO"],[LOG_PS2,"PS2"],[LOG_PIC,"PIC"],
[LOG_VGA,"VGA"],[LOG_PIT,"PIT"],[LOG_MOUSE,"MOUS"],[LOG_PCI,"PCI"],[LOG_BIOS,"BIOS"],[LOG_FLOPPY,"FLOP"],[LOG_SERIAL,"SERI"],[LOG_RTC,"RTC"],[LOG_HPET,"HPET"],[LOG_ACPI,"ACPI"],[LOG_APIC,"APIC"],[LOG_NET,"NET"],[LOG_VIRTIO,"VIO"],[LOG_9P,"9P"],[LOG_SB16,"SB16"]],FLAG_CARRY=1,FLAG_PARITY=4,FLAG_ADJUST=16,FLAG_ZERO=64,FLAG_SIGN=128,FLAG_TRAP=256,FLAG_INTERRUPT=512,FLAG_DIRECTION=1024,FLAG_OVERFLOW=2048,FLAG_IOPL=12288,FLAG_NT=16384,FLAG_RF=65536,FLAG_VM=131072,FLAG_AC=262144,FLAG_VIF=524288,FLAG_VIP=
1048576,FLAG_ID=2097152,FLAGS_DEFAULT=2,REG_EAX=0,REG_ECX=1,REG_EDX=2,REG_EBX=3,REG_ESP=4,REG_EBP=5,REG_ESI=6,REG_EDI=7,REG_ES=0,REG_CS=1,REG_SS=2,REG_DS=3,REG_FS=4,REG_GS=5,REG_LDTR=7,MMAP_BLOCK_BITS=17,MMAP_BLOCK_SIZE=1<<MMAP_BLOCK_BITS,CR0_PG=-2147483648,CR4_PAE=32,FW_CFG_SIGNATURE=0,FW_CFG_ID=1,FW_CFG_RAM_SIZE=3,FW_CFG_NB_CPUS=5,FW_CFG_MAX_CPUS=15,FW_CFG_NUMA=13,FW_CFG_FILE_DIR=25,FW_CFG_CUSTOM_START=32768,FW_CFG_FILE_START=49152,FW_CFG_SIGNATURE_QEMU=1431127377,WASM_TABLE_SIZE=900,WASM_TABLE_OFFSET=
1024,MIXER_CHANNEL_LEFT=0,MIXER_CHANNEL_RIGHT=1,MIXER_CHANNEL_BOTH=2,MIXER_SRC_MASTER=0,MIXER_SRC_PCSPEAKER=1,MIXER_SRC_DAC=2;function ScreenAdapter(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w,y,B,A){w.style.width="";w.style.height="";A&&(w.style.transform="");var E=w.getBoundingClientRect();A?w.style.transform=(1===y?"":" scaleX("+y+")")+(1===B?"":" scaleY("+B+")"):(0===y%1&&0===B%1?(e.style.imageRendering="crisp-edges",e.style.imageRendering="pixelated",e.style["-ms-interpolation-mode"]="nearest-neighbor"):(e.style.imageRendering="",e.style["-ms-interpolation-mode"]=""),A=window.devicePixelRatio||
1,0!==A%1&&(y/=A,B/=A));1!==y&&(w.style.width=E.width*y+"px");1!==B&&(w.style.height=E.height*B+"px")}console.assert(a,"1st argument must be a DOM container");var e=a.getElementsByTagName("canvas")[0],g=e.getContext("2d",{alpha:!1}),f=a.getElementsByTagName("div")[0],k=document.createElement("div"),m,l,n=1,p=1,t=1,r,q=!1,v,u,x,z=!1,C=this;a=new Uint16Array([199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,
250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var D=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,
9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),I=[],J,G=0;256>G;G++)J=127<G?a[G-128]:32>G?D[G]:G,I[G]=String.fromCharCode(J);g.imageSmoothingEnabled=!1;k.style.position="absolute";k.style.backgroundColor="#ccc";k.style.width="7px";k.style.display="inline-block";f.style.display="block";e.style.display="none";this.bus=b;b.register("screen-set-mode",function(w){this.set_mode(w)},this);b.register("screen-fill-buffer-end",function(w){this.update_buffer(w)},
this);b.register("screen-put-char",function(w){this.put_char(w[0],w[1],w[2],w[3],w[4])},this);b.register("screen-update-cursor",function(w){this.update_cursor(w[0],w[1])},this);b.register("screen-update-cursor-scanline",function(w){this.update_cursor_scanline(w[0],w[1])},this);b.register("screen-clear",function(){this.clear_screen()},this);b.register("screen-set-size-text",function(w){this.set_size_text(w[0],w[1])},this);b.register("screen-set-size-graphical",function(w){this.set_size_graphical(w[0],
w[1],w[2],w[3])},this);this.init=function(){this.set_size_text(80,25);this.timer()};this.make_screenshot=function(){const w=new Image;if(q)w.src=e.toDataURL("image/png");else{const y=[9,16],B=document.createElement("canvas");B.width=u*y[0];B.height=x*y[1];const A=B.getContext("2d");A.imageSmoothingEnabled=!1;A.font=window.getComputedStyle(f).font;A.textBaseline="top";for(let E=0;E<u;E++)for(let F=0;F<x;F++){const H=3*(F*u+E);A.fillStyle=c(v[H+1]);A.fillRect(E*y[0],F*y[1],y[0],y[1]);A.fillStyle=c(v[H+
2]);A.fillText(I[v[H]],E*y[0],F*y[1])}"none"!==k.style.display&&(A.fillStyle=k.style.backgroundColor,A.fillRect(l*y[0],m*y[1]+parseInt(k.style.marginTop,10)-1,parseInt(k.style.width,10),parseInt(k.style.height,10)));w.src=B.toDataURL("image/png")}try{window.open("").document.write(w.outerHTML)}catch(y){}};this.put_char=function(w,y,B,A,E){w<x&&y<u&&(y=3*(w*u+y),dbg_assert(0<=B&&256>B),v[y]=B,v[y+1]=A,v[y+2]=E,r[w]=1)};this.timer=function(){z||requestAnimationFrame(q?N:O)};var O=function(){for(var w=
0;w<x;w++)r[w]&&(C.text_update_row(w),r[w]=0);this.timer()}.bind(this),N=function(){this.bus.send("screen-fill-buffer");this.timer()}.bind(this);this.destroy=function(){z=!0};this.set_mode=function(w){(q=w)?(f.style.display="none",e.style.display="block"):(f.style.display="block",e.style.display="none")};this.clear_screen=function(){g.fillStyle="#000";g.fillRect(0,0,e.width,e.height)};this.set_size_text=function(w,y){if(w!==u||y!==x){r=new Int8Array(y);v=new Int32Array(w*y*3);u=w;for(x=y;f.childNodes.length>
y;)f.removeChild(f.firstChild);for(;f.childNodes.length<y;)f.appendChild(document.createElement("div"));for(w=0;w<y;w++)this.text_update_row(w);d(f,n,p,!0)}};this.set_size_graphical=function(w,y,B,A){DEBUG_SCREEN_LAYERS&&(w=B,y=A);e.style.display="block";e.width=w;e.height=y;t=640>=w&&2*w<window.innerWidth&&2*w<window.innerHeight?2:1;d(e,n*t,p*t,!1)};this.set_scale=function(w,y){n=w;p=y;d(f,n,p,!0);d(e,n*t,p*t,!1)};this.set_scale(n,p);this.update_cursor_scanline=function(w,y){w&32?k.style.display=
"none":(k.style.display="inline",k.style.height=Math.min(15,y-w)+"px",k.style.marginTop=Math.min(15,w)+"px")};this.update_cursor=function(w,y){if(w!==m||y!==l)r[w]=1,r[m]=1,m=w,l=y};this.text_update_row=function(w){var y=3*w*u,B;var A=f.childNodes[w];var E=document.createElement("div");for(var F=0;F<u;){var H=document.createElement("span");var K=v[y+1];var L=v[y+2];H.style.backgroundColor=c(K);H.style.color=c(L);for(B="";F<u&&v[y+1]===K&&v[y+2]===L;){var M=v[y];B+=I[M];dbg_assert(I[M]);F++;y+=3;if(w===
m)if(F===l)break;else if(F===l+1){E.appendChild(k);break}}H.textContent=B;E.appendChild(H)}A.parentNode.replaceChild(E,A)};this.update_buffer=function(w){DEBUG_SCREEN_LAYERS?(g.strokeStyle="#0F0",g.lineWidth=4,w.forEach(y=>{g.strokeRect(y.buffer_x,y.buffer_y,y.buffer_width,y.buffer_height)}),g.lineWidth=1):w.forEach(y=>{g.putImageData(y.image_data,y.screen_x-y.buffer_x,y.screen_y-y.buffer_y,y.buffer_x,y.buffer_y,y.buffer_width,y.buffer_height)})};this.init()};const VIRTIO_9P_F_MOUNT_TAG=0,VIRTIO_9P_MAX_TAGLEN=254;
var EPERM=1,ENOENT=2,EEXIST=17,EINVAL=22,EOPNOTSUPP=95,ENOTEMPTY=39,EPROTO=71,P9_SETATTR_MODE=1,P9_SETATTR_UID=2,P9_SETATTR_GID=4,P9_SETATTR_SIZE=8,P9_SETATTR_ATIME=16,P9_SETATTR_MTIME=32,P9_SETATTR_CTIME=64,P9_SETATTR_ATIME_SET=128,P9_SETATTR_MTIME_SET=256,P9_STAT_MODE_DIR=2147483648,P9_STAT_MODE_APPEND=1073741824,P9_STAT_MODE_EXCL=536870912,P9_STAT_MODE_MOUNT=268435456,P9_STAT_MODE_AUTH=134217728,P9_STAT_MODE_TMP=67108864,P9_STAT_MODE_SYMLINK=33554432,P9_STAT_MODE_LINK=16777216,P9_STAT_MODE_DEVICE=
8388608,P9_STAT_MODE_NAMED_PIPE=2097152,P9_STAT_MODE_SOCKET=1048576,P9_STAT_MODE_SETUID=524288,P9_STAT_MODE_SETGID=262144,P9_STAT_MODE_SETVTX=65536;const P9_LOCK_TYPE_RDLCK=0,P9_LOCK_TYPE_WRLCK=1,P9_LOCK_TYPE_UNLCK=2,P9_LOCK_TYPES=Object.freeze(["shared","exclusive","unlock"]),P9_LOCK_FLAGS_BLOCK=1,P9_LOCK_FLAGS_RECLAIM=2,P9_LOCK_SUCCESS=0,P9_LOCK_BLOCKED=1,P9_LOCK_ERROR=2,P9_LOCK_GRACE=3;var FID_NONE=-1,FID_INODE=1,FID_XATTR=2;
function Virtio9p(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.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[];this.virtio=new VirtIO(b,{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:[VIRTIO_9P_F_MOUNT_TAG,VIRTIO_F_VERSION_1,
VIRTIO_F_RING_EVENT_IDX,VIRTIO_F_RING_INDIRECT_DESC],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[d=>{if(0!==d)dbg_assert(!1,"Virtio9P Notified for non-existent queue: "+d+" (expected queue_id of 0)");else{for(;this.virtqueue.has_request();)d=this.virtqueue.pop_request(),this.ReceiveRequest(d);this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,
write:d=>{}}].concat(v86util.range(VIRTIO_9P_MAX_TAGLEN).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:e=>{}})))}});this.virtqueue=this.virtio.queues[0]}
Virtio9p.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};
Virtio9p.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])};Virtio9p.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};
Virtio9p.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Virtio9p.prototype.Reset=function(){this.fids=[]};Virtio9p.prototype.BuildReply=function(a,b,c){dbg_assert(0<=c,"9P: Negative payload size");marshall.Marshall(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&message.Debug("Error in 9p: payloadsize exceeds maximum length");this.replybuffersize=c+7};
Virtio9p.prototype.SendError=function(a,b,c){b=marshall.Marshall(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};Virtio9p.prototype.SendReply=function(a){dbg_assert(0<=this.replybuffersize,"9P: Negative replybuffersize");a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};
Virtio9p.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=marshall.Unmarshall(["w","b","h"],b,c),e=d[0],g=d[1],f=d[2];switch(g){case 8:e=this.fs.GetTotalSize();b=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=marshall.Marshall("wwddddddw".split(""),d,this.replybuffer,
7);this.BuildReply(g,f,e);this.SendReply(a);break;case 112:case 12:d=marshall.Unmarshall(["w","w"],b,c);var k=d[0];c=d[1];message.Debug("[open] fid="+k+", mode="+c);b=this.fids[k].inodeid;var m=this.fs.GetInode(b);message.Debug("file open "+this.fids[k].dbg_name);d=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[k].inodeid,function(){message.Debug("file opened "+this.fids[k].dbg_name+" tag:"+f);var t=[];t[0]=m.qid;t[1]=this.msize-24;marshall.Marshall(["Q","w"],t,this.replybuffer,7);this.BuildReply(g,
f,17);this.SendReply(a)}.bind(this));break;case 70:d=marshall.Unmarshall(["w","w","s"],b,c);b=d[0];k=d[1];e=d[2];message.Debug("[link] dfid="+b+", name="+e);d=this.fs.Link(this.fids[b].inodeid,this.fids[k].inodeid,e);if(0>d){e="";d===-EPERM?e="Operation not permitted":(e="Unknown error: "+-d,dbg_assert(!1,"[link]: Unexpected error code: "+-d));this.SendError(f,e,-d);this.SendReply(a);break}this.BuildReply(g,f,0);this.SendReply(a);break;case 16:d=marshall.Unmarshall(["w","s","s","w"],b,c);k=d[0];e=
d[1];b=d[2];d=d[3];message.Debug("[symlink] fid="+k+", name="+e+", symgt="+b+", gid="+d);b=this.fs.CreateSymlink(e,this.fids[k].inodeid,b);m=this.fs.GetInode(b);m.uid=this.fids[k].uid;m.gid=d;marshall.Marshall(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(g,f,13);this.SendReply(a);break;case 18:d=marshall.Unmarshall("wswwww".split(""),b,c);k=d[0];e=d[1];c=d[2];b=d[3];var l=d[4];d=d[5];message.Debug("[mknod] fid="+k+", name="+e+", major="+b+", minor="+l);b=this.fs.CreateNode(e,this.fids[k].inodeid,
b,l);m=this.fs.GetInode(b);m.mode=c;m.uid=this.fids[k].uid;m.gid=d;marshall.Marshall(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(g,f,13);this.SendReply(a);break;case 22:d=marshall.Unmarshall(["w"],b,c);k=d[0];m=this.fs.GetInode(this.fids[k].inodeid);message.Debug("[readlink] fid="+k+" name="+this.fids[k].dbg_name+" target="+m.symlink);e=marshall.Marshall(["s"],[m.symlink],this.replybuffer,7);this.BuildReply(g,f,e);this.SendReply(a);break;case 72:d=marshall.Unmarshall(["w","s","w","w"],b,c);
k=d[0];e=d[1];c=d[2];d=d[3];message.Debug("[mkdir] fid="+k+", name="+e+", mode="+c+", gid="+d);b=this.fs.CreateDirectory(e,this.fids[k].inodeid);m=this.fs.GetInode(b);m.mode=c|S_IFDIR;m.uid=this.fids[k].uid;m.gid=d;marshall.Marshall(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(g,f,13);this.SendReply(a);break;case 14:d=marshall.Unmarshall(["w","s","w","w","w"],b,c);k=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[k].inodeid]);message.Debug("[create] fid="+k+", name="+
e+", flags="+b+", mode="+c+", gid="+d);b=this.fs.CreateFile(e,this.fids[k].inodeid);this.fids[k].inodeid=b;this.fids[k].type=FID_INODE;this.fids[k].dbg_name=e;m=this.fs.GetInode(b);m.uid=this.fids[k].uid;m.gid=d;m.mode=c;marshall.Marshall(["Q","w"],[m.qid,this.msize-24],this.replybuffer,7);this.BuildReply(g,f,17);this.SendReply(a);break;case 52:d=marshall.Unmarshall("wbwddws".split(""),b,c);k=d[0];b=d[2];e=0===d[4]?Infinity:d[4];e=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);message.Debug("[lock] fid="+
k+", type="+P9_LOCK_TYPES[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.Lock(this.fids[k].inodeid,e,b);marshall.Marshall(["b"],[d],this.replybuffer,7);this.BuildReply(g,f,1);this.SendReply(a);break;case 54:d=marshall.Unmarshall("wbddws".split(""),b,c);k=d[0];e=0===d[3]?Infinity:d[3];e=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);message.Debug("[getlock] fid="+k+", type="+P9_LOCK_TYPES[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.GetLock(this.fids[k].inodeid,
e);d||(d=e,d.type=P9_LOCK_TYPE_UNLCK);e=marshall.Marshall(["b","d","d","w","s"],[d.type,d.start,Infinity===d.length?0:d.length,d.proc_id,d.client_id],this.replybuffer,7);this.BuildReply(g,f,e);this.SendReply(a);break;case 24:d=marshall.Unmarshall(["w","d"],b,c);k=d[0];m=this.fs.GetInode(this.fids[k].inodeid);message.Debug("[getattr]: fid="+k+" name="+this.fids[k].dbg_name+" request mask="+d[1]);if(!m||m.status===STATUS_UNLINKED){message.Debug("getattr: unlinked");this.SendError(f,"No such file or directory",
ENOENT);this.SendReply(a);break}d[0]|=4096;d[0]=d[1];d[1]=m.qid;d[2]=m.mode;d[3]=m.uid;d[4]=m.gid;d[5]=m.nlinks;d[6]=m.major<<8|m.minor;d[7]=m.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(m.size/512+1);d[10]=m.atime;d[11]=0;d[12]=m.mtime;d[13]=0;d[14]=m.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;marshall.Marshall("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(g,f,153);this.SendReply(a);break;case 26:d=marshall.Unmarshall("wwwwwddddd".split(""),b,c);k=d[0];m=this.fs.GetInode(this.fids[k].inodeid);
message.Debug("[setattr]: fid="+k+" request mask="+d[1]+" name="+this.fids[k].dbg_name);d[1]&P9_SETATTR_MODE&&(m.mode=d[2]);d[1]&P9_SETATTR_UID&&(m.uid=d[3]);d[1]&P9_SETATTR_GID&&(m.gid=d[4]);d[1]&P9_SETATTR_ATIME&&(m.atime=Math.floor((new Date).getTime()/1E3));d[1]&P9_SETATTR_MTIME&&(m.mtime=Math.floor((new Date).getTime()/1E3));d[1]&P9_SETATTR_CTIME&&(m.ctime=Math.floor((new Date).getTime()/1E3));d[1]&P9_SETATTR_ATIME_SET&&(m.atime=d[6]);d[1]&P9_SETATTR_MTIME_SET&&(m.mtime=d[8]);d[1]&P9_SETATTR_SIZE&&
await this.fs.ChangeSize(this.fids[k].inodeid,d[5]);this.BuildReply(g,f,0);this.SendReply(a);break;case 50:d=marshall.Unmarshall(["w","d"],b,c);k=d[0];this.BuildReply(g,f,0);this.SendReply(a);break;case 40:case 116:d=marshall.Unmarshall(["w","d","w"],b,c);k=d[0];e=d[1];l=d[2];m=this.fs.GetInode(this.fids[k].inodeid);40==g&&message.Debug("[treaddir]: fid="+k+" offset="+e+" count="+l);116==g&&message.Debug("[read]: fid="+k+" ("+this.fids[k].dbg_name+") offset="+e+" count="+l+" fidtype="+this.fids[k].type);
if(!m||m.status===STATUS_UNLINKED){message.Debug("read/treaddir: unlinked");this.SendError(f,"No such file or directory",ENOENT);this.SendReply(a);break}if(this.fids[k].type==FID_XATTR)for(m.caps.length<e+l&&(l=m.caps.length-e),d=0;d<l;d++)this.replybuffer[11+d]=m.caps[e+d];else this.fs.OpenInode(this.fids[k].inodeid,void 0),d=this.fids[k].inodeid,l=Math.min(l,this.replybuffer.length-11),m.size<e+l?l=m.size-e:40==g&&(l=this.fs.RoundToDirentry(d,e+l)-e),e>m.size&&(l=0),this.bus.send("9p-read-start",
[this.fids[k].dbg_name]),d=await this.fs.Read(d,e,l),this.bus.send("9p-read-end",[this.fids[k].dbg_name,l]),d&&this.replybuffer.set(d,11);marshall.Marshall(["w"],[l],this.replybuffer,7);this.BuildReply(g,f,4+l);this.SendReply(a);break;case 118:d=marshall.Unmarshall(["w","d","w"],b,c);k=d[0];e=d[1];l=d[2];d=this.fids[k].dbg_name;message.Debug("[write]: fid="+k+" ("+d+") offset="+e+" count="+l+" fidtype="+this.fids[k].type);if(this.fids[k].type===FID_XATTR){this.SendError(f,"Setxattr not supported",
EOPNOTSUPP);this.SendReply(a);break}else await this.fs.Write(this.fids[k].inodeid,e,l,b.subarray(c.offset));this.bus.send("9p-write-end",[d,l]);marshall.Marshall(["w"],[l],this.replybuffer,7);this.BuildReply(g,f,4);this.SendReply(a);break;case 74:d=marshall.Unmarshall(["w","s","w","s"],b,c);c=d[0];l=d[1];e=d[2];b=d[3];message.Debug("[renameat]: oldname="+l+" newname="+b);d=await this.fs.Rename(this.fids[c].inodeid,l,this.fids[e].inodeid,b);if(0>d){e="";d===-ENOENT?e="No such file or directory":d===
-EPERM?e="Operation not permitted":d===-ENOTEMPTY?e="Directory not empty":(e="Unknown error: "+-d,dbg_assert(!1,"[renameat]: Unexpected error code: "+-d));this.SendError(f,e,-d);this.SendReply(a);break}TRACK_FILENAMES&&(d=this.fs.Search(this.fids[e].inodeid,b),this.update_dbg_name(d,b));this.BuildReply(g,f,0);this.SendReply(a);break;case 76:d=marshall.Unmarshall(["w","s","w"],b,c);c=d[0];e=d[1];b=d[2];message.Debug("[unlink]: dirfd="+c+" name="+e+" flags="+b);k=this.fs.Search(this.fids[c].inodeid,
e);if(-1==k){this.SendError(f,"No such file or directory",ENOENT);this.SendReply(a);break}d=this.fs.Unlink(this.fids[c].inodeid,e);if(0>d){e="";d===-ENOTEMPTY?e="Directory not empty":d===-EPERM?e="Operation not permitted":(e="Unknown error: "+-d,dbg_assert(!1,"[unlink]: Unexpected error code: "+-d));this.SendError(f,e,-d);this.SendReply(a);break}this.BuildReply(g,f,0);this.SendReply(a);break;case 100:d=marshall.Unmarshall(["w","s"],b,c);message.Debug("[version]: msize="+d[0]+" version="+d[1]);this.msize=
d[0];e=marshall.Marshall(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(g,f,e);this.SendReply(a);break;case 104:d=marshall.Unmarshall(["w","w","s","s","w"],b,c);k=d[0];e=d[4];message.Debug("[attach]: fid="+k+" afid="+hex8(d[1])+" uname="+d[2]+" aname="+d[3]);this.fids[k]=this.Createfid(0,FID_INODE,e,"");m=this.fs.GetInode(this.fids[k].inodeid);marshall.Marshall(["Q"],[m.qid],this.replybuffer,7);this.BuildReply(g,f,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=
marshall.Unmarshall(["h"],b,c);message.Debug("[flush] "+f);this.BuildReply(g,f,0);this.SendReply(a);break;case 110:d=marshall.Unmarshall(["w","w","h"],b,c);k=d[0];l=d[1];var n=d[2];message.Debug("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+n);if(0==n){this.fids[l]=this.Createfid(this.fids[k].inodeid,FID_INODE,this.fids[k].uid,this.fids[k].dbg_name);marshall.Marshall(["h"],[0],this.replybuffer,7);this.BuildReply(g,f,2);this.SendReply(a);break}e=[];for(d=0;d<n;d++)e.push("s");c=marshall.Unmarshall(e,
b,c);b=this.fids[k].inodeid;e=9;var p=0;message.Debug("walk in dir "+this.fids[k].dbg_name+" to: "+c.toString());for(d=0;d<n;d++){b=this.fs.Search(b,c[d]);if(-1==b){message.Debug("Could not find: "+c[d]);break}e+=marshall.Marshall(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,e);p++;this.fids[l]=this.Createfid(b,FID_INODE,this.fids[k].uid,c[d])}marshall.Marshall(["h"],[p],this.replybuffer,7);this.BuildReply(g,f,e-7);this.SendReply(a);break;case 120:d=marshall.Unmarshall(["w"],b,c);message.Debug("[clunk]: fid="+
d[0]);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=FID_NONE);this.BuildReply(g,f,0);this.SendReply(a);break;case 32:d=marshall.Unmarshall(["w","s","d","w"],b,c);k=d[0];e=d[1];c=d[2];b=d[3];message.Debug("[txattrcreate]: fid="+k+" name="+e+" attr_size="+c+" flags="+b);this.fids[k].type=FID_XATTR;this.BuildReply(g,f,0);this.SendReply(a);break;case 30:d=marshall.Unmarshall(["w","w","s"],b,c);k=d[0];e=d[2];
message.Debug("[xattrwalk]: fid="+d[0]+" newfid="+d[1]+" name="+d[2]);this.SendError(f,"Setxattr not supported",EOPNOTSUPP);this.SendReply(a);break;default:message.Debug("Error in Virtio9p: Unknown id "+g+" received"),message.Abort()}};var DEBUG=!1,LOG_TO_FILE=!1,LOG_ALL_IO=!1,DUMP_GENERATED_WASM=!1,DUMP_UNCOMPILED_ASSEMBLY=!1,TRACK_FILENAMES=!1,LOG_LEVEL=LOG_ALL&~LOG_PS2&~LOG_PIT&~LOG_VIRTIO&~LOG_9P&~LOG_PIC&~LOG_DMA&~LOG_SERIAL&~LOG_NET&~LOG_FLOPPY&~LOG_DISK&~LOG_VGA&~LOG_SB16,DEBUG_SCREEN_LAYERS=DEBUG&&!1,ENABLE_HPET=DEBUG&&!1,TIME_PER_FRAME=1,TSC_RATE=1E6,APIC_TIMER_FREQ=TSC_RATE;function IO(a){this.ports=[];this.cpu=a;for(var b=0;65536>b;b++)this.ports[b]=this.create_empty_entry();var c=a.memory_size[0];for(b=0;b<<MMAP_BLOCK_BITS<c;b++)a.memory_map_read8[b]=a.memory_map_write8[b]=void 0,a.memory_map_read32[b]=a.memory_map_write32[b]=void 0;this.mmap_register(c,4294967296-c,function(d){dbg_log("Read from unmapped memory space, addr="+h(d>>>0,8),LOG_IO);return 255},function(d,e){dbg_log("Write to unmapped memory space, addr="+h(d>>>0,8)+" value="+h(e,2),LOG_IO)},function(d){dbg_log("Read from unmapped memory space, addr="+
h(d>>>0,8),LOG_IO);return-1},function(d,e){dbg_log("Write to unmapped memory space, addr="+h(d>>>0,8)+" value="+h(e>>>0,8),LOG_IO)})}IO.prototype.create_empty_entry=function(){return{read8:this.empty_port_read8,read16:this.empty_port_read16,read32:this.empty_port_read32,write8:this.empty_port_write,write16:this.empty_port_write,write32:this.empty_port_write,device:void 0}};IO.prototype.empty_port_read8=function(){return 255};IO.prototype.empty_port_read16=function(){return 65535};
IO.prototype.empty_port_read32=function(){return-1};IO.prototype.empty_port_write=function(a){};
IO.prototype.register_read=function(a,b,c,d,e){dbg_assert("number"===typeof a);dbg_assert("object"===typeof b);dbg_assert(!c||"function"===typeof c);dbg_assert(!d||"function"===typeof d);dbg_assert(!e||"function"===typeof e);dbg_assert(c||d||e);if(DEBUG){var g=function(f){dbg_assert(!1,"Overlapped read"+f+" "+h(a,4)+" ("+b.name+")");return-1>>>32-f|0};c||(c=g.bind(this,8));d||(d=g.bind(this,16));e||(e=g.bind(this,32))}c&&(this.ports[a].read8=c);d&&(this.ports[a].read16=d);e&&(this.ports[a].read32=
e);this.ports[a].device=b};
IO.prototype.register_write=function(a,b,c,d,e){dbg_assert("number"===typeof a);dbg_assert("object"===typeof b);dbg_assert(!c||"function"===typeof c);dbg_assert(!d||"function"===typeof d);dbg_assert(!e||"function"===typeof e);dbg_assert(c||d||e);if(DEBUG){var g=function(f){dbg_assert(!1,"Overlapped write"+f+" "+h(a)+" ("+b.name+")")};c||(c=g.bind(this,8));d||(d=g.bind(this,16));e||(e=g.bind(this,32))}c&&(this.ports[a].write8=c);d&&(this.ports[a].write16=d);e&&(this.ports[a].write32=e);this.ports[a].device=
b};IO.prototype.register_read_consecutive=function(a,b,c,d,e,g){function f(){return c.call(this)|d.call(this)<<8}function k(){return e.call(this)|g.call(this)<<8}function m(){return c.call(this)|d.call(this)<<8|e.call(this)<<16|g.call(this)<<24}dbg_assert(4===arguments.length||6===arguments.length);e&&g?(this.register_read(a,b,c,f,m),this.register_read(a+1,b,d),this.register_read(a+2,b,e,k),this.register_read(a+3,b,g)):(this.register_read(a,b,c,f),this.register_read(a+1,b,d))};
IO.prototype.register_write_consecutive=function(a,b,c,d,e,g){function f(l){c.call(this,l&255);d.call(this,l>>8&255)}function k(l){e.call(this,l&255);g.call(this,l>>8&255)}function m(l){c.call(this,l&255);d.call(this,l>>8&255);e.call(this,l>>16&255);g.call(this,l>>>24)}dbg_assert(4===arguments.length||6===arguments.length);e&&g?(this.register_write(a,b,c,f,m),this.register_write(a+1,b,d),this.register_write(a+2,b,e,k),this.register_write(a+3,b,g)):(this.register_write(a,b,c,f),this.register_write(a+
1,b,d))};IO.prototype.mmap_read32_shim=function(a){var b=this.cpu.memory_map_read8[a>>>MMAP_BLOCK_BITS];return b(a)|b(a+1)<<8|b(a+2)<<16|b(a+3)<<24};IO.prototype.mmap_write32_shim=function(a,b){var c=this.cpu.memory_map_write8[a>>>MMAP_BLOCK_BITS];c(a,b&255);c(a+1,b>>8&255);c(a+2,b>>16&255);c(a+3,b>>>24)};
IO.prototype.mmap_register=function(a,b,c,d,e,g){dbg_log("mmap_register addr="+h(a>>>0,8)+" size="+h(b,8),LOG_IO);dbg_assert(0===(a&MMAP_BLOCK_SIZE-1));dbg_assert(b&&0===(b&MMAP_BLOCK_SIZE-1));e||(e=this.mmap_read32_shim.bind(this));g||(g=this.mmap_write32_shim.bind(this));for(a>>>=MMAP_BLOCK_BITS;0<b;a++)this.cpu.memory_map_read8[a]=c,this.cpu.memory_map_write8[a]=d,this.cpu.memory_map_read32[a]=e,this.cpu.memory_map_write32[a]=g,b-=MMAP_BLOCK_SIZE};
IO.prototype.port_write8=function(a,b){var c=this.ports[a];(c.write8===this.empty_port_write||LOG_ALL_IO)&&dbg_log("write8 port #"+h(a,4)+" <- "+h(b,2)+this.get_port_description(a),LOG_IO);return c.write8.call(c.device,b)};IO.prototype.port_write16=function(a,b){var c=this.ports[a];(c.write16===this.empty_port_write||LOG_ALL_IO)&&dbg_log("write16 port #"+h(a,4)+" <- "+h(b,4)+this.get_port_description(a),LOG_IO);return c.write16.call(c.device,b)};
IO.prototype.port_write32=function(a,b){var c=this.ports[a];(c.write32===this.empty_port_write||LOG_ALL_IO)&&dbg_log("write32 port #"+h(a,4)+" <- "+h(b>>>0,8)+this.get_port_description(a),LOG_IO);return c.write32.call(c.device,b)};IO.prototype.port_read8=function(a){var b=this.ports[a];(b.read8===this.empty_port_read8||LOG_ALL_IO)&&dbg_log("read8 port #"+h(a,4)+this.get_port_description(a),LOG_IO);b=b.read8.call(b.device);dbg_assert(256>b,"8 bit port returned large value: "+h(a));return b};
IO.prototype.port_read16=function(a){var b=this.ports[a];(b.read16===this.empty_port_read16||LOG_ALL_IO)&&dbg_log("read16 port #"+h(a,4)+this.get_port_description(a),LOG_IO);b=b.read16.call(b.device);dbg_assert(65536>b&&0<=b,"16 bit port returned large value: "+h(a));return b};
IO.prototype.port_read32=function(a){var b=this.ports[a];(b.read32===this.empty_port_read32||LOG_ALL_IO)&&dbg_log("read32 port #"+h(a,4)+this.get_port_description(a),LOG_IO);a=b.read32.call(b.device);dbg_assert((a|0)===a);return a};
var debug_port_list={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",
179:"PORT_SMI_STATUS",212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",1008:"PORT_FD_BASE",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",
1296:"PORT_QEMU_CFG_CTL",1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};IO.prototype.get_port_description=function(a){return debug_port_list[a]?" ("+debug_port_list[a]+")":""};function v86(a,b){this.stopping=this.running=!1;this.tick_counter=0;this.worker=null;this.cpu=new CPU(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;a.register("cpu-init",this.init,this);a.register("cpu-run",this.run,this);a.register("cpu-stop",this.stop,this);a.register("cpu-restart",this.restart,this);this.register_yield()}v86.prototype.run=function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};
v86.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_run();this.next_tick(a)}};v86.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};v86.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};v86.prototype.stop=function(){this.running&&(this.stopping=!0)};v86.prototype.destroy=function(){this.unregister_yield()};
v86.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};v86.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};
if("undefined"!==typeof process)v86.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},v86.prototype.register_yield=function(){},v86.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){globalThis.onmessage=function(b){const c=b.data.t;1>c?postMessage(b.data.tick):setTimeout(()=>postMessage(b.data.tick),c)}}v86.prototype.register_yield=function(){const b=URL.createObjectURL(new Blob(["("+
a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};v86.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};v86.prototype.unregister_yield=function(){this.worker.terminate();this.worker=null}}else v86.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},v86.prototype.register_yield=function(){},v86.prototype.unregister_yield=function(){};v86.prototype.save_state=function(){return this.cpu.save_state()};
v86.prototype.restore_state=function(a){return this.cpu.restore_state(a)};if("object"===typeof performance&&performance.now)v86.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");v86.microtick=a.now.bind(a)}else v86.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;var goog=goog||{};goog.exportSymbol=function(){};goog.exportProperty=function(){};var v86util=v86util||{};v86util.pads=function(a,b){return(a||0===a?a+"":"").padEnd(b," ")};v86util.pad0=function(a,b){return(a||0===a?a+"":"").padStart(b,"0")};v86util.zeros=function(a){return Array(a).fill(0)};v86util.range=function(a){return Array.from(Array(a).keys())};
v86util.view=function(a,b,c,d){return new Proxy({},{get:function(e,g,f){e=new a(b.buffer,c,d);f=e[g];if("function"===typeof f)return f.bind(e);dbg_assert(/^\d+$/.test(g)||"buffer"===g||"length"===g||"BYTES_PER_ELEMENT"===g||"byteOffset"===g);return f},set:function(e,g,f,k){dbg_assert(/^\d+$/.test(g));(new a(b.buffer,c,d))[g]=f;return!0}})};function h(a,b){a=a?a.toString(16):"";return"0x"+v86util.pad0(a.toUpperCase(),b||1)}
function hex_dump(a){function b(k,m){return v86util.pad0(k.toString(16).toUpperCase(),m)}const c=[];let d=0;for(;d+15<a.length;d+=16){var e=b(d,5)+" ";for(var g=0;16>g;g++)e+=b(a[d+g],2)+" ";e+=" ";for(g=0;16>g;g++){var f=a[d+g];e+=33<=f&&34!==f&&92!==f&&126>=f?String.fromCharCode(f):"."}c.push(e)}for(e=b(d,5)+" ";d<a.length;d++)e+=b(a[d],2)+" ";g=d&15;e+=" ".repeat(16-g);e+=" ";for(f=0;f<g;f++){const k=a[d+f];e+=33<=k&&34!==k&&92!==k&&126>=k?String.fromCharCode(k):"."}c.push(e);return"\n"+
c.join("\n")+"\n"}if("undefined"!==typeof crypto&&crypto.getRandomValues){let a=new Int32Array(1);v86util.get_rand_int=function(){crypto.getRandomValues(a);return a[0]}}else if("undefined"!==typeof require){const a=require("crypto");v86util.get_rand_int=function(){return a.randomBytes(4).readInt32LE(0)}}else dbg_assert(!1,"Unsupported platform: No cryptographic random values");
(function(){if("function"===typeof Math.clz32)v86util.int_log2_byte=function(d){dbg_assert(0<d);dbg_assert(256>d);return 31-Math.clz32(d)},v86util.int_log2=function(d){dbg_assert(0<d);return 31-Math.clz32(d)};else{for(var a=new Int8Array(256),b=0,c=-2;256>b;b++)b&b-1||c++,a[b]=c;v86util.int_log2_byte=function(d){dbg_assert(0<d);dbg_assert(256>d);return a[d]};v86util.int_log2=function(d){d>>>=0;dbg_assert(0<d);var e=d>>>16;if(e){var g=e>>>8;return g?24+a[g]:16+a[e]}return(g=d>>>8)?8+a[g]:a[d]}}})();
function ByteQueue(a){var b=new Uint8Array(a),c,d;dbg_assert(0===(a&a-1));this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function FloatQueue(a){this.size=a;this.data=new Float32Array(a);this.length=this.end=this.start=0;dbg_assert(0===(a&a-1))}
FloatQueue.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};FloatQueue.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;return a}};
FloatQueue.prototype.shift_block=function(a){var b=new Float32Array(a);a>this.length&&(a=this.length);var c=this.start+a,d=this.data.subarray(this.start,c);b.set(d);c>=this.size&&(c-=this.size,b.set(this.data.subarray(0,c),d.length));this.start=c;this.length-=a;return b};FloatQueue.prototype.peek=function(){if(this.length)return this.data[this.start]};FloatQueue.prototype.clear=function(){this.length=this.end=this.start=0};function CircularQueue(a){this.data=[];this.index=0;this.size=a}
CircularQueue.prototype.add=function(a){this.data[this.index]=a;this.index=(this.index+1)%this.size};CircularQueue.prototype.toArray=function(){return[].slice.call(this.data,this.index).concat([].slice.call(this.data,0,this.index))};CircularQueue.prototype.clear=function(){this.data=[];this.index=0};CircularQueue.prototype.set=function(a){this.data=a;this.index=0};function dump_file(a,b){a instanceof Array||(a=[a]);a=new Blob(a);download(a,b)}
function download(a,b){var c=document.createElement("a");c.download=b;c.href=window.URL.createObjectURL(a);c.dataset.downloadurl=["application/octet-stream",c.download,c.href].join(":");document.createEvent?(a=document.createEvent("MouseEvent"),a.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(a)):c.click();window.URL.revokeObjectURL(c.href)}
v86util.Bitmap=function(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof ArrayBuffer?this.view=new Uint8Array(a):dbg_assert(!1,"v86util.Bitmap: Invalid argument")};v86util.Bitmap.prototype.set=function(a,b){const c=a>>3;a=1<<(a&7);this.view[c]=b?this.view[c]|a:this.view[c]&~a};v86util.Bitmap.prototype.get=function(a){return this.view[a>>3]>>(a&7)&1};v86util.Bitmap.prototype.get_buffer=function(){return this.view.buffer};
v86util.load_file="undefined"===typeof XMLHttpRequest?load_file_nodejs:load_file;
function load_file(a,b,c){function d(){const m=c||0;setTimeout(()=>{load_file(a,b,m+1)},1E3*([1,1,2,3,5,8,13,21][m]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";if(b.headers)for(var g=Object.keys(b.headers),f=0;f<g.length;f++){var k=g[f];e.setRequestHeader(k,b.headers[k])}b.range&&(g=b.range.start,e.setRequestHeader("Range","bytes="+g+"-"+(g+b.range.length-1)),e.onreadystatechange=function(){200===e.status&&e.abort()});e.onload=function(m){4===
e.readyState&&(200!==e.status&&206!==e.status?(console.error("Loading the image "+a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d()):e.response&&b.done&&b.done(e.response,e))};e.onerror=function(m){console.error("Loading the image "+a+" failed",m);d()};b.progress&&(e.onprogress=function(m){b.progress(m)});e.send(null)}
function load_file_nodejs(a,b){let c=require("fs");b.range?(dbg_assert(!b.as_json),c.open(a,"r",(d,e)=>{if(d)throw d;let g=b.range.length;var f=Buffer.allocUnsafe(g);c.read(e,f,0,g,b.range.start,(k,m)=>{if(k)throw k;dbg_assert(m===g);b.done&&b.done(new Uint8Array(f));c.close(e,l=>{if(l)throw l;})})})):c.readFile(a,{encoding:b.as_json?"utf-8":null},function(d,e){d?console.log("Could not read file:",a,d):(d=e,d=b.as_json?JSON.parse(d):(new Uint8Array(d)).buffer,b.done(d))})}
v86util.read_sized_string_from_mem=function(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,b>>>0,c>>>0)))};(function(){function a(f){dbg_assert(f instanceof ArrayBuffer);this.buffer=f;this.byteLength=f.byteLength;this.onprogress=this.onload=void 0}function b(f,k,m){this.filename=f;this.byteLength=k;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=m;this.cache_reads=!!m;this.onprogress=this.onload=void 0}function c(f,k,m,l){const n=f.match(/(.*)(\..*)/);n?(this.basename=n[1],this.extension=n[2]):(this.basename=f,this.extension="");this.block_cache=new Map;this.block_cache_is_write=
new Set;this.byteLength=k;this.fixed_chunk_size=m;this.partfile_alt_format=!!l;this.cache_reads=!!m;this.onprogress=this.onload=void 0}function d(f){this.file=f;this.byteLength=f.size;1073741824<f.size&&console.warn("SyncFileBuffer: Allocating buffer of "+(f.size>>20)+" MB ...");this.buffer=new ArrayBuffer(f.size);this.onprogress=this.onload=void 0}function e(f){this.file=f;this.byteLength=f.size;this.block_cache=new Map;this.block_cache_is_write=new Set;this.onprogress=this.onload=void 0}v86util.SyncBuffer=
a;v86util.AsyncXHRBuffer=b;v86util.AsyncXHRPartfileBuffer=c;v86util.AsyncFileBuffer=e;v86util.SyncFileBuffer=d;a.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};a.prototype.get=function(f,k,m){dbg_assert(f+k<=this.byteLength);m(new Uint8Array(this.buffer,f,k))};a.prototype.set=function(f,k,m){dbg_assert(f+k.byteLength<=this.byteLength);(new Uint8Array(this.buffer,f,k.byteLength)).set(k);m()};a.prototype.get_buffer=function(f){f(this.buffer)};a.prototype.get_state=function(){const f=
[];f[0]=this.byteLength;f[1]=new Uint8Array(this.buffer);return f};a.prototype.set_state=function(f){this.byteLength=f[0];this.buffer=f[1].slice().buffer};b.prototype.load=function(){void 0!==this.byteLength?this.onload&&this.onload(Object.create(null)):g(this.filename,(f,k)=>{if(f)throw Error("Cannot use: "+this.filename+". "+f);dbg_assert(0<=k);this.byteLength=k;this.onload&&this.onload(Object.create(null))})};b.prototype.get_from_cache=function(f,k){var m=k/256;f/=256;for(var l=0;l<m;l++)if(!this.block_cache.get(f+
l))return;if(1===m)return this.block_cache.get(f);k=new Uint8Array(k);for(l=0;l<m;l++)k.set(this.block_cache.get(f+l),256*l);return k};b.prototype.get=function(f,k,m){dbg_assert(f+k<=this.byteLength);dbg_assert(0===f%256);dbg_assert(0===k%256);dbg_assert(k);var l=this.get_from_cache(f,k);if(l)m(l);else{var n=f,p=k;this.fixed_chunk_size&&(n=f-f%this.fixed_chunk_size,p=Math.ceil((f-n+k)/this.fixed_chunk_size)*this.fixed_chunk_size);v86util.load_file(this.filename,{done:function(t){t=new Uint8Array(t);
this.handle_read(n,p,t);n==f&&p==k?m(t):m(t.subarray(f-n,f-n+k))}.bind(this),range:{start:n,length:p}})}};b.prototype.set=function(f,k,m){var l=k.length;dbg_assert(f+k.byteLength<=this.byteLength);dbg_assert(0===f%256);dbg_assert(0===l%256);dbg_assert(l);f/=256;l/=256;for(var n=0;n<l;n++){var p=this.block_cache.get(f+n);void 0===p&&(p=new Uint8Array(256),this.block_cache.set(f+n,p));var t=k.subarray(256*n,256*(n+1));p.set(t);dbg_assert(p.byteLength===t.length);this.block_cache_is_write.add(f+n)}m()};
b.prototype.handle_read=function(f,k,m){f/=256;k/=256;for(var l=0;l<k;l++){var n=this.block_cache.get(f+l);n?m.set(n,256*l):this.cache_reads&&(n=new Uint8Array(256),n.set(m.subarray(256*l,256*(l+1))),this.block_cache.set(f+l,n))}};b.prototype.get_buffer=function(f){f()};b.prototype.get_state=function(){const f=[],k=[];for(let [m,l]of this.block_cache)dbg_assert(isFinite(m)),this.block_cache_is_write.has(m)&&k.push([m,l]);f[0]=k;return f};b.prototype.set_state=function(f){f=f[0];this.block_cache.clear();
this.block_cache_is_write.clear();for(let [k,m]of f)dbg_assert(isFinite(k)),this.block_cache.set(k,m),this.block_cache_is_write.add(k)};c.prototype.load=function(){void 0===this.byteLength&&dbg_assert(!1);this.onload&&this.onload(Object.create(null))};c.prototype.get=function(f,k,m){dbg_assert(f+k<=this.byteLength);dbg_assert(0===f%256);dbg_assert(0===k%256);dbg_assert(k);var l=this.get_from_cache(f,k);if(l)m(l);else if(this.fixed_chunk_size){const p=Math.floor(f/this.fixed_chunk_size),t=f-p*this.fixed_chunk_size;
dbg_assert(0<=t);const r=Math.ceil((t+k)/this.fixed_chunk_size),q=new Uint8Array(r*this.fixed_chunk_size);let v=0;for(let u=0;u<r;u++){var n=(p+u)*this.fixed_chunk_size;l=this.partfile_alt_format?this.basename+"-"+(p+u+"").padStart(8,"0")+this.extension:this.basename+"-"+n+"-"+(n+this.fixed_chunk_size)+this.extension;(n=this.get_from_cache(n,this.fixed_chunk_size))?(q.set(n,u*this.fixed_chunk_size),v++,v===r&&(l=q.subarray(t,t+k),m(l))):v86util.load_file(l,{done:function(x){var z=u*this.fixed_chunk_size;
x=new Uint8Array(x);this.handle_read((p+u)*this.fixed_chunk_size,this.fixed_chunk_size|0,x);q.set(x,z);v++;v===r&&(z=q.subarray(t,t+k),m(z))}.bind(this)})}}else v86util.load_file(this.basename+"-"+f+"-"+(f+k)+this.extension,{done:function(p){dbg_assert(p.byteLength===k);p=new Uint8Array(p);this.handle_read(f,k,p);m(p)}.bind(this)})};c.prototype.get_from_cache=b.prototype.get_from_cache;c.prototype.set=b.prototype.set;c.prototype.handle_read=b.prototype.handle_read;c.prototype.get_state=b.prototype.get_state;
c.prototype.set_state=b.prototype.set_state;d.prototype.load=function(){this.load_next(0)};d.prototype.load_next=function(f){var k=new FileReader;k.onload=function(l){l=new Uint8Array(l.target.result);(new Uint8Array(this.buffer,f)).set(l);this.load_next(f+4194304)}.bind(this);if(this.onprogress)this.onprogress({loaded:f,total:this.byteLength,lengthComputable:!0});if(f<this.byteLength){var m=this.file.slice(f,Math.min(f+4194304,this.byteLength));k.readAsArrayBuffer(m)}else this.file=void 0,this.onload&&
this.onload({buffer:this.buffer})};d.prototype.get=a.prototype.get;d.prototype.set=a.prototype.set;d.prototype.get_buffer=a.prototype.get_buffer;d.prototype.get_state=a.prototype.get_state;d.prototype.set_state=a.prototype.set_state;e.prototype.load=function(){this.onload&&this.onload(Object.create(null))};e.prototype.get=function(f,k,m){dbg_assert(0===f%256);dbg_assert(0===k%256);dbg_assert(k);var l=this.get_from_cache(f,k);l?m(l):(l=new FileReader,l.onload=function(n){n=new Uint8Array(n.target.result);
this.handle_read(f,k,n);m(n)}.bind(this),l.readAsArrayBuffer(this.file.slice(f,f+k)))};e.prototype.get_from_cache=b.prototype.get_from_cache;e.prototype.set=b.prototype.set;e.prototype.handle_read=b.prototype.handle_read;e.prototype.get_state=b.prototype.get_state;e.prototype.set_state=b.prototype.set_state;e.prototype.get_buffer=function(f){f()};e.prototype.get_as_file=function(f){for(var k=[],m=Array.from(this.block_cache.keys()).sort(function(r,q){return r-q}),l=0,n=0;n<m.length;n++){var p=m[n],
t=this.block_cache.get(p);p*=256;dbg_assert(p>=l);p!==l&&(k.push(this.file.slice(l,p)),l=p);k.push(t);l+=t.length}l!==this.file.size&&k.push(this.file.slice(l));f=new File(k,f);dbg_assert(f.size===this.file.size);return f};var g="undefined"===typeof XMLHttpRequest?function(f,k){require("fs").stat(f,(m,l)=>{m?k(m):k(null,l.size)})}:function(f,k){v86util.load_file(f,{done:(m,l)=>{m=l.getResponseHeader("Content-Range")||"";(l=m.match(/\/(\d+)\s*$/))?k(null,+l[1]):k("`Range: bytes=...` header not supported (Got `"+
m+"`)")},headers:{Range:"bytes=0-0"}})}})();var CDROM_SECTOR_SIZE=2048,HD_SECTOR_SIZE=512;
function IDEDevice(a,b,c,d,e,g){this.master=new IDEInterface(this,a,b,d,e,0,g);this.slave=new IDEInterface(this,a,c,!1,e,1,g);this.current_interface=this.master;this.cpu=a;0===e?(this.ata_port=496,this.irq=14,this.pci_id=240):1===e?(this.ata_port=368,this.irq=15,this.pci_id=248):dbg_assert(!1,"IDE device with nr "+e+" ignored",LOG_DISK);this.ata_port_high=this.ata_port|516;this.master_port=46080;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,this.ata_port&255|1,this.ata_port>>8,0,0,this.ata_port_high&
255|1,this.ata_port_high>>8,0,0,0,0,0,0,0,0,0,0,this.master_port&255|1,this.master_port>>8,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,this.irq,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[{size:8},{size:4},void 0,void 0,{size:16}];this.name="ide"+e;this.device_control=2;a.io.register_read(this.ata_port|7,this,function(){dbg_log("lower irq",
LOG_DISK);this.cpu.device_lower_irq(this.irq);return this.read_status()});a.io.register_read(this.ata_port_high|2,this,this.read_status);a.io.register_write(this.ata_port_high|2,this,this.write_control);a.io.register_read(this.ata_port|0,this,function(){return this.current_interface.read_data(1)},function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});a.io.register_read(this.ata_port|1,this,function(){dbg_log("Read error: "+h(this.current_interface.error&
255)+" slave="+(this.current_interface===this.slave),LOG_DISK);return this.current_interface.error&255});a.io.register_read(this.ata_port|2,this,function(){dbg_log("Read bytecount: "+h(this.current_interface.bytecount&255),LOG_DISK);return this.current_interface.bytecount&255});a.io.register_read(this.ata_port|3,this,function(){dbg_log("Read sector: "+h(this.current_interface.sector&255),LOG_DISK);return this.current_interface.sector&255});a.io.register_read(this.ata_port|4,this,function(){dbg_log("Read 1F4: "+
h(this.current_interface.cylinder_low&255),LOG_DISK);return this.current_interface.cylinder_low&255});a.io.register_read(this.ata_port|5,this,function(){dbg_log("Read 1F5: "+h(this.current_interface.cylinder_high&255),LOG_DISK);return this.current_interface.cylinder_high&255});a.io.register_read(this.ata_port|6,this,function(){dbg_log("Read 1F6",LOG_DISK);return this.current_interface.drive_head&255});a.io.register_write(this.ata_port|0,this,function(f){this.current_interface.write_data_port8(f)},
function(f){this.current_interface.write_data_port16(f)},function(f){this.current_interface.write_data_port32(f)});a.io.register_write(this.ata_port|1,this,function(f){dbg_log("1F1/lba_count: "+h(f),LOG_DISK);this.master.lba_count=(this.master.lba_count<<8|f)&65535;this.slave.lba_count=(this.slave.lba_count<<8|f)&65535});a.io.register_write(this.ata_port|2,this,function(f){dbg_log("1F2/bytecount: "+h(f),LOG_DISK);this.master.bytecount=(this.master.bytecount<<8|f)&65535;this.slave.bytecount=(this.slave.bytecount<<
8|f)&65535});a.io.register_write(this.ata_port|3,this,function(f){dbg_log("1F3/sector: "+h(f),LOG_DISK);this.master.sector=(this.master.sector<<8|f)&65535;this.slave.sector=(this.slave.sector<<8|f)&65535});a.io.register_write(this.ata_port|4,this,function(f){dbg_log("1F4/sector low: "+h(f),LOG_DISK);this.master.cylinder_low=(this.master.cylinder_low<<8|f)&65535;this.slave.cylinder_low=(this.slave.cylinder_low<<8|f)&65535});a.io.register_write(this.ata_port|5,this,function(f){dbg_log("1F5/sector high: "+
h(f),LOG_DISK);this.master.cylinder_high=(this.master.cylinder_high<<8|f)&65535;this.slave.cylinder_high=(this.slave.cylinder_high<<8|f)&65535});a.io.register_write(this.ata_port|6,this,function(f){var k=f&16;dbg_log("1F6/drive: "+h(f,2),LOG_DISK);k?(dbg_log("Slave",LOG_DISK),this.current_interface=this.slave):this.current_interface=this.master;this.master.drive_head=f;this.slave.drive_head=f;this.master.is_lba=this.slave.is_lba=f>>6&1;this.master.head=this.slave.head=f&15});this.dma_command=this.dma_status=
this.prdt_addr=0;a.io.register_write(this.ata_port|7,this,function(f){dbg_log("lower irq",LOG_DISK);this.cpu.device_lower_irq(this.irq);this.current_interface.ata_command(f)});a.io.register_read(this.master_port|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(this.master_port|4,this,void 0,void 0,this.dma_set_addr);a.io.register_read(this.master_port,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(this.master_port,this,this.dma_write_command8,void 0,this.dma_write_command);
a.io.register_read(this.master_port|2,this,this.dma_read_status);a.io.register_write(this.master_port|2,this,this.dma_write_status);a.io.register_read(this.master_port|8,this,function(){dbg_log("DMA read 0x8",LOG_DISK);return 0});a.io.register_read(this.master_port|10,this,function(){dbg_log("DMA read 0xA",LOG_DISK);return 0});a.devices.pci.register_device(this);DEBUG&&Object.seal(this)}
IDEDevice.prototype.read_status=function(){if(this.current_interface.buffer){var a=this.current_interface.status;dbg_log("ATA read status: "+h(a,2),LOG_DISK);return a}return 0};IDEDevice.prototype.write_control=function(a){dbg_log("set device control: "+h(a,2)+" interrupts "+(a&2?"disabled":"enabled"),LOG_DISK);a&4&&(dbg_log("Reset via control port",LOG_DISK),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control=a};
IDEDevice.prototype.dma_read_addr=function(){dbg_log("dma get address: "+h(this.prdt_addr,8),LOG_DISK);return this.prdt_addr};IDEDevice.prototype.dma_set_addr=function(a){dbg_log("dma set address: "+h(a,8),LOG_DISK);this.prdt_addr=a};IDEDevice.prototype.dma_read_status=function(){dbg_log("DMA read status: "+h(this.dma_status),LOG_DISK);return this.dma_status};IDEDevice.prototype.dma_write_status=function(a){dbg_log("DMA set status: "+h(a),LOG_DISK);this.dma_status&=~(a&6)};
IDEDevice.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};IDEDevice.prototype.dma_read_command8=function(){dbg_log("DMA read command: "+h(this.dma_command),LOG_DISK);return this.dma_command};IDEDevice.prototype.dma_write_command=function(a){dbg_log("DMA write command: "+h(a),LOG_DISK);this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};
IDEDevice.prototype.dma_write_command8=function(a){dbg_log("DMA write command8: "+h(a),LOG_DISK);let b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 37:case 200:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:dbg_log("Spurious dma command write, current command: "+
h(this.current_interface.current_command),LOG_DISK),dbg_assert(!1)}};IDEDevice.prototype.push_irq=function(){0===(this.device_control&2)&&(dbg_log("push irq",LOG_DISK),this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};
IDEDevice.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.ata_port;a[3]=this.irq;a[4]=this.pci_id;a[5]=this.ata_port_high;a[6]=this.master_port;a[7]=this.name;a[8]=this.device_control;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};
IDEDevice.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.ata_port=a[2];this.irq=a[3];this.pci_id=a[4];this.ata_port_high=a[5];this.master_port=a[6];this.name=a[7];this.device_control=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]};
function IDEInterface(a,b,c,d,e,g,f){this.device=a;this.bus=f;this.nr=e;this.cpu=b;this.buffer=c;this.sector_size=d?CDROM_SECTOR_SIZE:HD_SECTOR_SIZE;this.is_atapi=d;this.cylinder_count=this.sectors_per_track=this.head_count=this.sector_count=0;this.buffer&&(this.sector_count=this.buffer.byteLength/this.sector_size,this.sector_count!==(this.sector_count|0)&&(dbg_log("Warning: Disk size not aligned with sector size",LOG_DISK),this.sector_count=Math.ceil(this.sector_count)),d?(this.head_count=1,this.sectors_per_track=
0):(this.head_count=16,this.sectors_per_track=63),this.cylinder_count=this.sector_count/this.head_count/this.sectors_per_track,this.cylinder_count!==(this.cylinder_count|0)&&(dbg_log("Warning: Rounding up cylinder count. Choose different head number",LOG_DISK),this.cylinder_count=Math.floor(this.cylinder_count)),a=b.devices.rtc,a.cmos_write(CMOS_BIOS_DISKTRANSFLAG,a.cmos_read(CMOS_BIOS_DISKTRANSFLAG)|1<<4*this.nr),a.cmos_write(CMOS_DISK_DATA,a.cmos_read(CMOS_DISK_DATA)&15|240),b=CMOS_DISK_DRIVE1_CYL,
a.cmos_write(b+0,this.cylinder_count&255),a.cmos_write(b+1,this.cylinder_count>>8&255),a.cmos_write(b+2,this.head_count&255),a.cmos_write(b+3,255),a.cmos_write(b+4,255),a.cmos_write(b+5,200),a.cmos_write(b+6,this.cylinder_count&255),a.cmos_write(b+7,this.cylinder_count>>8&255),a.cmos_write(b+8,this.sectors_per_track&255));this.stats={sectors_read:0,sectors_written:0,bytes_read:0,bytes_written:0,loading:!1};this.buffer=c;this.drive_head=this.head=this.cylinder_high=this.cylinder_low=this.lba_count=
this.sector=this.bytecount=this.is_lba=0;this.status=80;this.sectors_per_drq=128;this.data_pointer=this.error=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_atapi_command=this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;Object.seal(this)}
IDEInterface.prototype.device_reset=function(){this.is_atapi?(this.status=0,this.sector=this.error=this.bytecount=1,this.cylinder_low=20,this.cylinder_high=235):(this.status=81,this.sector=this.error=this.bytecount=1,this.cylinder_high=this.cylinder_low=0);this.cancel_io_operations()};IDEInterface.prototype.push_irq=function(){this.device.push_irq()};
IDEInterface.prototype.ata_command=function(a){dbg_log("ATA Command: "+h(a)+" slave="+(this.drive_head>>4&1),LOG_DISK);if(this.buffer)switch(this.current_command=a,this.error=0,a){case 8:dbg_log("ATA device reset",LOG_DISK);this.data_length=this.data_end=this.data_pointer=0;this.device_reset();this.push_irq();break;case 16:this.status=80;this.cylinder_low=0;this.push_irq();break;case 248:this.status=80;a=this.sector_count-1;this.sector=a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;
this.drive_head=this.drive_head&240|a>>24&15;this.push_irq();break;case 39:this.status=80;a=this.sector_count-1;this.sector=a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;this.sector|=a>>24<<8&65280;this.push_irq();break;case 32:case 36:case 41:case 196:this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197:this.ata_write_sectors(a);break;case 144:this.push_irq();this.error=257;this.status=80;break;case 145:this.status=80;this.push_irq();break;case 160:this.is_atapi&&(this.status=
88,this.data_allocate(12),this.data_end=12,this.bytecount=1,this.push_irq());break;case 161:dbg_log("ATA identify packet device",LOG_DISK);this.is_atapi?(this.create_identify_packet(),this.status=88,this.cylinder_low=20,this.cylinder_high=235):this.status=65;this.push_irq();break;case 198:dbg_log("Logical sectors per DRQ Block: "+h(this.bytecount&255),LOG_DISK);this.sectors_per_drq=this.bytecount&255;this.status=80;this.push_irq();break;case 37:case 200:this.ata_read_sectors_dma(a);break;case 53:case 202:this.ata_write_sectors_dma(a);
break;case 64:dbg_log("read verify sectors",LOG_DISK);this.status=80;this.push_irq();break;case 218:dbg_log("Unimplemented: get media status",LOG_DISK);this.status=65;this.error=4;this.push_irq();break;case 224:dbg_log("ATA standby immediate",LOG_DISK);this.status=80;this.push_irq();break;case 225:dbg_log("ATA idle immediate",LOG_DISK);this.status=80;this.push_irq();break;case 231:dbg_log("ATA flush cache",LOG_DISK);this.status=80;this.push_irq();break;case 236:dbg_log("ATA identify device",LOG_DISK);
if(this.is_atapi){this.status=65;this.error=4;this.push_irq();break}this.create_identify_packet();this.status=88;this.push_irq();break;case 234:dbg_log("flush cache ext",LOG_DISK);this.status=80;this.push_irq();break;case 239:dbg_log("set features: "+h(this.bytecount&255),LOG_DISK);this.status=80;this.push_irq();break;case 222:this.status=80;this.push_irq();break;case 245:dbg_log("security freeze lock",LOG_DISK);this.status=80;this.push_irq();break;case 249:dbg_log("Unimplemented: set max address",
LOG_DISK);this.status=65;this.error=4;break;default:dbg_assert(!1,"New ATA cmd on 1F7: "+h(a),LOG_DISK),this.status=65,this.error=4}else dbg_log("abort: No buffer",LOG_DISK),this.error=4,this.status=65,this.push_irq()};
IDEInterface.prototype.atapi_handle=function(){dbg_log("ATAPI Command: "+h(this.data[0])+" slave="+(this.drive_head>>4&1),LOG_DISK);this.data_pointer=0;this.current_atapi_command=this.data[0];switch(this.current_atapi_command){case 0:dbg_log("test unit ready",LOG_DISK);this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;this.data[0]=240;this.data[2]=5;this.data[7]=8;break;case 18:var a=this.data[4];
this.status=88;dbg_log("inquiry: "+h(this.data[1],2)+" length="+a,LOG_DISK);this.data.set([5,128,1,49,31,0,0,0,83,79,78,89,32,32,32,32,67,68,45,82,79,77,32,67,68,85,45,49,48,48,48,32,49,46,49,97]);this.data_end=this.data_length=Math.min(36,a);break;case 26:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 37:a=this.sector_count-1;this.data_set(new Uint8Array([a>>24&255,a>>16&255,
a>>8&255,a&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status=88;break;case 40:this.lba_count&1?this.atapi_read_dma(this.data):this.atapi_read(this.data);break;case 66:a=this.data[8];this.data_allocate(Math.min(8,a));this.data_end=this.data_length;dbg_log("read q subcode: length="+a,LOG_DISK);this.status=88;break;case 67:a=this.data[8]|this.data[7]<<8;var b=this.data[9]>>6;this.data_allocate(a);this.data_end=this.data_length;dbg_log("read toc: "+h(b,
2)+" length="+a+" "+(this.data[1]&2)+" "+h(this.data[6]),LOG_DISK);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])):dbg_assert(!1,"Unimplemented format: "+b);this.status=88;break;case 70:a=this.data[8]|this.data[7]<<8;a=Math.min(a,32);this.data_allocate(a);this.data_end=this.data_length;this.data[0]=a-4>>24&255;this.data[1]=a-4>>16&255;this.data[2]=a-4>>8&
255;this.data[3]=a-4&255;this.data[6]=8;this.data[10]=3;this.status=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 82:dbg_log("Unimplemented ATAPI command: "+h(this.data[0]),LOG_DISK);this.status=81;this.data_length=0;this.error=80;break;case 90:a=this.data[8]|this.data[7]<<8;b=this.data[2];dbg_log("mode sense: "+h(b)+" length="+a,LOG_DISK);42===b&&this.data_allocate(Math.min(30,a));this.data_end=this.data_length;this.status=88;break;case 189:this.data_allocate(this.data[9]|
this.data[8]<<8);this.data_end=this.data_length;this.data[5]=1;this.status=88;break;case 74:this.status=81;this.data_length=0;this.error=80;dbg_log("Unimplemented ATAPI command: "+h(this.data[0]),LOG_DISK);break;case 190:dbg_log("Unimplemented ATAPI command: "+h(this.data[0]),LOG_DISK);this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;default:this.status=81,this.data_length=0,this.error=80,dbg_log("Unimplemented ATAPI command: "+h(this.data[0]),LOG_DISK),dbg_assert(!1)}this.bytecount=
this.bytecount&-8|2;0===(this.status&128)&&this.push_irq();0===(this.status&128)&&0===this.data_length&&(this.bytecount|=1,this.status&=-9)};IDEInterface.prototype.do_write=function(){this.status=80;dbg_assert(this.data_length<=this.data.length);var a=this.data.subarray(0,this.data_length);dbg_assert(0===this.data_length%512);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,a,function(){});this.report_write(this.data_length)};
IDEInterface.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;dbg_log("CD read lba="+h(b)+" lbacount="+h(c)+" bytecount="+h(d)+" flags="+h(a),LOG_DISK);this.data_length=0;var g=this.cylinder_high<<8&65280|this.cylinder_low&255;dbg_log(h(this.cylinder_high,2)+" "+h(this.cylinder_low,2),LOG_DISK);this.cylinder_low=this.cylinder_high=0;65535===g&&g--;g>d&&(g=d);e>=this.buffer.byteLength?(dbg_assert(!1,"CD read: Outside of disk end="+
h(e+d)+" size="+h(this.buffer.byteLength),LOG_DISK),this.status=255,this.push_irq()):0===d?(this.status=80,this.data_pointer=0):(d=Math.min(d,this.buffer.byteLength-e),this.status=208,this.report_read_start(),this.read_buffer(e,d,f=>{dbg_log("cd read: data arrived",LOG_DISK);this.data_set(f);this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();this.data_end=g&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.cylinder_low=this.data_end&255;this.cylinder_high=this.data_end>>
8&255;this.report_read_end(d)}))};
IDEInterface.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;dbg_log("CD read DMA lba="+h(b)+" lbacount="+h(c)+" bytecount="+h(d)+" flags="+h(a),LOG_DISK);e>=this.buffer.byteLength?(dbg_assert(!1,"CD read: Outside of disk end="+h(e+d)+" size="+h(this.buffer.byteLength),LOG_DISK),this.status=255,this.push_irq()):(this.status=208,this.report_read_start(),this.read_buffer(e,d,g=>{dbg_log("atapi_read_dma: Data arrived");
this.report_read_end(d);this.status=88;this.bytecount=this.bytecount&-8|2;this.data_set(g);this.do_atapi_dma()}))};
IDEInterface.prototype.do_atapi_dma=function(){if(0===(this.device.dma_status&1))dbg_log("do_atapi_dma: Status not set",LOG_DISK);else if(0===(this.status&8))dbg_log("do_atapi_dma: DRQ not set",LOG_DISK);else{dbg_log("atapi dma transfer len="+this.data_length,LOG_DISK);var a=this.device.prdt_addr,b=0,c=this.data;do{var d=this.cpu.read32s(a),e=this.cpu.read16(a+4),g=this.cpu.read8(a+7)&128;e||(e=65536);dbg_log("dma read dest="+h(d)+" count="+h(e)+" datalen="+h(this.data_length),LOG_DISK);this.cpu.write_blob(c.subarray(b,
Math.min(b+e,this.data_length)),d);b+=e;a+=8;if(b>=this.data_length&&!g){dbg_log("leave early end="+ +g+" offset="+h(b)+" data_length="+h(this.data_length)+" cmd="+h(this.current_command),LOG_DISK);break}}while(!g);dbg_log("end offset="+b,LOG_DISK);this.status=80;this.device.dma_status&=-2;this.bytecount=this.bytecount&-8|3;this.push_irq()}};
IDEInterface.prototype.read_data=function(a){if(this.data_pointer<this.data_end){dbg_assert(this.data_pointer+a-1<this.data_end);dbg_assert(0===this.data_pointer%a,h(this.data_pointer)+" "+a);var b=1===a?this.data[this.data_pointer]:2===a?this.data16[this.data_pointer>>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;0===(this.data_pointer&(0===(this.data_end&4095)?4095:255))&&dbg_log("Read 1F0: "+h(this.data[this.data_pointer],2)+" cur="+h(this.data_pointer)+" cnt="+h(this.data_length),
LOG_DISK);this.data_pointer>=this.data_end&&this.read_end();return b}dbg_log("Read 1F0: empty",LOG_DISK);this.data_pointer+=a;return 0};
IDEInterface.prototype.read_end=function(){dbg_log("read_end cmd="+h(this.current_command)+" data_pointer="+h(this.data_pointer)+" end="+h(this.data_end)+" length="+h(this.data_length),LOG_DISK);if(160===this.current_command)if(this.data_end===this.data_length)this.status=80,this.bytecount=this.bytecount&-8|3,this.push_irq();else{this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();var a=this.cylinder_high<<8&65280|this.cylinder_low&255;this.data_end+a>this.data_length?(this.cylinder_low=
this.data_length-this.data_end&255,this.cylinder_high=this.data_length-this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=a;dbg_log("data_end="+h(this.data_end),LOG_DISK)}else this.error=0,this.data_pointer>=this.data_length?this.status=80:(196===this.current_command||41===this.current_command?(a=Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512),dbg_assert(0===a%1)):(dbg_assert(32===this.current_command||36===this.current_command),a=1),this.ata_advance(this.current_command,
a),this.data_end+=512*a,this.status=88),this.push_irq()};
IDEInterface.prototype.write_data_port=function(a,b){dbg_assert(0===this.data_pointer%b);this.data_pointer>=this.data_end?dbg_log("Redundant write to data port: "+h(a)+" count="+h(this.data_end)+" cur="+h(this.data_pointer),LOG_DISK):((0===(this.data_pointer+b&(0===(this.data_end&4095)?4095:255))||20>this.data_end)&&dbg_log("Data port: "+h(a>>>0)+" count="+h(this.data_end)+" cur="+h(this.data_pointer),LOG_DISK),1===b?this.data[this.data_pointer++]=a:2===b?(this.data16[this.data_pointer>>>1]=a,this.data_pointer+=
2):(this.data32[this.data_pointer>>>2]=a,this.data_pointer+=4),dbg_assert(this.data_pointer<=this.data_end),this.data_pointer===this.data_end&&this.write_end())};IDEInterface.prototype.write_data_port8=function(a){this.write_data_port(a,1)};IDEInterface.prototype.write_data_port16=function(a){this.write_data_port(a,2)};IDEInterface.prototype.write_data_port32=function(a){this.write_data_port(a,4)};
IDEInterface.prototype.write_end=function(){160===this.current_command?this.atapi_handle():(dbg_log("write_end data_pointer="+h(this.data_pointer)+" data_length="+h(this.data_length),LOG_DISK),this.data_pointer>=this.data_length?this.do_write():(dbg_assert(48===this.current_command||52===this.current_command||197===this.current_command,"Unexpected command: "+h(this.current_command)),this.status=88,this.data_end+=512,this.push_irq()))};
IDEInterface.prototype.ata_advance=function(a,b){dbg_log("Advance sectors="+b+" old_bytecount="+this.bytecount,LOG_DISK);this.bytecount-=b;36===a||41===a||52===a||57===a||37===a||53===a?(a=b+this.get_lba48(),this.sector=a&255|a>>16&65280,this.cylinder_low=a>>8&255,this.cylinder_high=a>>16&255):this.is_lba?(a=b+this.get_lba28(),this.sector=a&255,this.cylinder_low=a>>8&255,this.cylinder_high=a>>16&255,this.head=this.head&-16|a&15):(a=b+this.get_chs(),b=a/(this.head_count*this.sectors_per_track)|0,this.cylinder_low=
b&255,this.cylinder_high=b>>8&255,this.head=(a/this.sectors_per_track|0)%this.head_count&15,this.sector=a%this.sectors_per_track+1&255,dbg_assert(a===this.get_chs()))};
IDEInterface.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);b=this.get_lba(b);var d=32===a||36===a,e=c*this.sector_size,g=b*this.sector_size;dbg_log("ATA read cmd="+h(a)+" mode="+(this.is_lba?"lba":"chs")+" lba="+h(b)+" lbacount="+h(c)+" bytecount="+h(e),LOG_DISK);g+e>this.buffer.byteLength?(dbg_assert(!1,"ATA read: Outside of disk",LOG_DISK),this.status=255,this.push_irq()):(this.status=192,this.report_read_start(),this.read_buffer(g,e,f=>{dbg_log("ata_read: Data arrived",
LOG_DISK);this.data_set(f);this.status=88;this.data_end=d?512:Math.min(e,512*this.sectors_per_drq);this.ata_advance(a,d?1:Math.min(c,this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};
IDEInterface.prototype.ata_read_sectors_dma=function(a){var b=37===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;dbg_log("ATA DMA read lba="+h(b)+" lbacount="+h(a)+" bytecount="+h(c),LOG_DISK);d+c>this.buffer.byteLength?(dbg_assert(!1,"ATA read: Outside of disk",LOG_DISK),this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)};
IDEInterface.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);a=this.get_lba(a);var c=b*this.sector_size,d=a*this.sector_size;dbg_assert(a<this.buffer.byteLength);this.report_read_start();var e=this.device.prdt_addr;this.read_buffer(d,c,g=>{dbg_log("do_ata_read_sectors_dma: Data arrived",LOG_DISK);var f=this.device.prdt_addr,k=0;dbg_assert(e===f);do{var m=this.cpu.read32s(f),l=this.cpu.read16(f+4),n=this.cpu.read8(f+7)&128;l||(l=65536,dbg_log("dma: prd count was 0",
LOG_DISK));dbg_log("dma read transfer dest="+h(m)+" prd_count="+h(l),LOG_DISK);this.cpu.write_blob(g.subarray(k,k+l),m);k+=l;f+=8}while(!n);dbg_assert(k===c);this.ata_advance(this.current_command,b);this.status=80;this.device.dma_status&=-2;this.current_command=-1;this.push_irq();this.report_read_end(c)})};
IDEInterface.prototype.ata_write_sectors=function(a){var b=52===a||57===a,c=this.get_count(b);b=this.get_lba(b);a=48===a||52===a;var d=c*this.sector_size,e=b*this.sector_size;dbg_log("ATA write lba="+h(b)+" mode="+(this.is_lba?"lba":"chs")+" lbacount="+h(c)+" bytecount="+h(d),LOG_DISK);e+d>this.buffer.byteLength?(dbg_assert(!1,"ATA write: Outside of disk",LOG_DISK),this.status=255,this.push_irq()):(this.status=88,this.data_allocate_noclear(d),this.data_end=a?512:Math.min(d,512*this.sectors_per_drq),
this.write_dest=e)};IDEInterface.prototype.ata_write_sectors_dma=function(a){var b=53===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;dbg_log("ATA DMA write lba="+h(b)+" lbacount="+h(a)+" bytecount="+h(c),LOG_DISK);d+c>this.buffer.byteLength?(dbg_assert(!1,"ATA DMA write: Outside of disk",LOG_DISK),this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)};
IDEInterface.prototype.do_ata_write_sectors_dma=function(){var a=53===this.current_command,b=this.get_count(a),c=this.get_lba(a);a=b*this.sector_size;c*=this.sector_size;var d=this.device.prdt_addr,e=0;dbg_log("prdt addr: "+h(d,8),LOG_DISK);const g=new Uint8Array(a);do{var f=this.cpu.read32s(d),k=this.cpu.read16(d+4),m=this.cpu.read8(d+7)&128;k||(k=65536,dbg_log("dma: prd count was 0",LOG_DISK));dbg_log("dma write transfer dest="+h(f)+" prd_count="+h(k),LOG_DISK);f=this.cpu.mem8.subarray(f,f+k);dbg_assert(f.length===
k);g.set(f,e);e+=k;d+=8}while(!m);dbg_assert(e===g.length);this.buffer.set(c,g,()=>{dbg_log("dma write completed",LOG_DISK);this.ata_advance(this.current_command,b);this.status=80;this.push_irq();this.device.dma_status&=-2;this.current_command=-1});this.report_write(a)};
IDEInterface.prototype.get_chs=function(){var a=this.cylinder_low&255|this.cylinder_high<<8&65280,b=this.head,c=this.sector&255;dbg_log("get_chs: c="+a+" h="+b+" s="+c,LOG_DISK);return(a*this.head_count+b)*this.sectors_per_track+c-1};IDEInterface.prototype.get_lba28=function(){return this.sector&255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|(this.head&15)<<24};
IDEInterface.prototype.get_lba48=function(){return(this.sector&255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|this.sector>>8<<24&4278190080)>>>0};IDEInterface.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};IDEInterface.prototype.get_count=function(a){a?(a=this.bytecount,0===a&&(a=65536)):(a=this.bytecount&255,0===a&&(a=256));return a};
IDEInterface.prototype.create_identify_packet=function(){if(this.drive_head&16)this.data_allocate(0);else{for(var a=0;512>a;a++)this.data[a]=0;a=Math.min(16383,this.cylinder_count);this.data_set([64,this.is_atapi?133:0,a,a>>8,0,0,this.head_count,this.head_count>>8,this.sectors_per_track/512,this.sectors_per_track/512>>8,0,2,this.sectors_per_track,this.sectors_per_track>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,2,4,0,0,0,0,0,0,0,0,0,56,118,32,54,68,72,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a,a>>8,this.head_count,this.head_count>>8,this.sectors_per_track,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,160===this.current_command?0:7,160===this.current_command?0:4,0,0,30,0,30,0,30,0,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,126,0,0,0,0,0,0,116,0,64,0,64,0,116,0,64,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255]);this.data_end=this.data_length=512}};IDEInterface.prototype.data_allocate=function(a){this.data_allocate_noclear(a);for(var b=0;b<a+3>>2;b++)this.data32[b]=0};
IDEInterface.prototype.data_allocate_noclear=function(a){this.data.length<a&&(this.data=new Uint8Array(a+3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};IDEInterface.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};IDEInterface.prototype.report_read_start=function(){this.stats.loading=!0;this.bus.send("ide-read-start")};
IDEInterface.prototype.report_read_end=function(a){this.stats.loading=!1;var b=a/this.sector_size|0;this.stats.sectors_read+=b;this.stats.bytes_read+=a;this.bus.send("ide-read-end",[this.nr,a,b])};IDEInterface.prototype.report_write=function(a){var b=a/this.sector_size|0;this.stats.sectors_written+=b;this.stats.bytes_written+=a;this.bus.send("ide-write-end",[this.nr,a,b])};
IDEInterface.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++;this.in_progress_io_ids.add(d);this.buffer.get(a,b,e=>{if(this.cancelled_io_ids.delete(d))dbg_assert(!this.in_progress_io_ids.has(d));else{var g=this.in_progress_io_ids.delete(d);dbg_assert(g);c(e)}})};IDEInterface.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_ids)this.cancelled_io_ids.add(a);this.in_progress_io_ids.clear()};
IDEInterface.prototype.get_state=function(){var a=[];a[0]=this.bytecount;a[1]=this.cylinder_count;a[2]=this.cylinder_high;a[3]=this.cylinder_low;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.drive_head;a[10]=this.error;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.lba_count;a[16]=this.data;a[17]=this.data_length;a[18]=this.sector;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;a[23]=this.status;
a[24]=this.write_dest;a[25]=this.current_command;a[26]=this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a};
IDEInterface.prototype.set_state=function(a){this.bytecount=a[0];this.cylinder_count=a[1];this.cylinder_high=a[2];this.cylinder_low=a[3];this.data_pointer=a[4];this.drive_head=a[9];this.error=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.lba_count=a[15];this.data=a[16];this.data_length=a[17];this.sector=a[18];this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status=a[23];this.write_dest=a[24];this.current_command=
a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28])};var PCI_CONFIG_ADDRESS=3320,PCI_CONFIG_DATA=3324;
function PCI(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=new Int32Array(this.pci_response.buffer);this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=
a.io;a.io.register_write(PCI_CONFIG_DATA,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],c)});a.io.register_write(PCI_CONFIG_DATA+1,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,c)});a.io.register_write(PCI_CONFIG_DATA+2,this,function(c){this.pci_write8(this.pci_addr32[0]+2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(PCI_CONFIG_DATA+3,this,function(c){this.pci_write8(this.pci_addr32[0]+
3|0,c)});a.io.register_read_consecutive(PCI_CONFIG_DATA,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});a.io.register_read_consecutive(PCI_CONFIG_ADDRESS,this,function(){return this.pci_status[0]},function(){return this.pci_status[1]},function(){return this.pci_status[2]},function(){return this.pci_status[3]});a.io.register_write_consecutive(PCI_CONFIG_ADDRESS,this,function(c){this.pci_addr[0]=
c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?(dbg_log("CPU reboot via PCI"),a.reboot_internal()):this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,
pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}PCI.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};
PCI.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var g=d[4+e];if(g&1){var f=c.pci_bars[e];this.set_io_bars(f,f.original_bar&65534,g&65534)}}this.device_spaces[b].set(d)}else c&&dbg_log("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+c.name+")"),d&&dbg_log("Warning: While restoring PCI device: Device doesn't exist in current configuration but does in snapshot (device "+
h(b,2)+")")}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};
PCI.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+h(a,4));d+=" dev="+h(c,2);d+=" addr="+h(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<c.byteLength?c[b>>2]:0,d+=" "+h(this.pci_addr32[0]>>>0,8)+" -> "+h(this.pci_response32[0]>>>0,8),b>=c.byteLength&&(d+=" (undef)"),d+=" ("+this.devices[a].name+")",dbg_log(d,LOG_PCI)):(this.pci_response32[0]=
-1,this.pci_status32[0]=0)};PCI.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(dbg_assert(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+h(a)+")"),dbg_log("PCI write8 dev="+h(c>>3,2)+" ("+e.name+") addr="+h(a,4)+" value="+h(b,2),LOG_PCI),d[a]=b)};
PCI.prototype.pci_write16=function(a,b){dbg_assert(0===(a&1));var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(16<=a&&44>a?dbg_log("Warning: PCI: Expected 32-bit write, got 16-bit (addr: "+h(a)+")"):(dbg_assert(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+h(a)+")"),dbg_log("PCI writ16 dev="+h(c>>3,2)+" ("+e.name+") addr="+h(a,4)+" value="+h(b,4),LOG_PCI),d[a>>>1]=b))};
PCI.prototype.pci_write32=function(a,b){dbg_assert(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var g=a-16>>2,f=e.pci_bars[g];dbg_log("BAR"+g+" exists="+(f?"y":"n")+" changed to "+h(b>>>0)+" dev="+h(c>>3,2)+" ("+e.name+") ",LOG_PCI);f?(dbg_assert(!(f.size&f.size-1),"bar size should be power of 2"),c=a>>2,e=d[c]&1,-1===(b|3|f.size-1)?(b=~(f.size-1)|e,0===e&&(d[c]=b)):0===e&&(g=f.original_bar,(b&-16)!==(g&-16)&&dbg_log("Warning: Changing memory bar not supported, ignored",
LOG_PCI),d[c]=g),1===e&&(dbg_assert(1===e),e=d[c]&65534,g=b&65534,dbg_log("io bar changed from "+h(e>>>0,8)+" to "+h(g>>>0,8)+" size="+f.size,LOG_PCI),this.set_io_bars(f,e,g),d[c]=b|1)):d[a>>2]=0;dbg_log("BAR effective value: "+h(d[a>>2]>>>0),LOG_PCI)}else 48===a?(dbg_log("PCI write rom address dev="+h(c>>3,2)+" ("+e.name+") value="+h(b>>>0,8),LOG_PCI),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?dbg_log("PCI write dev="+h(c>>3,2)+" ("+e.name+") addr="+h(a,4)+
" value="+h(b>>>0,8),LOG_PCI):(dbg_log("PCI write dev="+h(c>>3,2)+" ("+e.name+") addr="+h(a,4)+" value="+h(b>>>0,8),LOG_PCI),d[a>>>2]=b)};
PCI.prototype.register_device=function(a){dbg_assert(void 0!==a.pci_id);dbg_assert(void 0!==a.pci_space);dbg_assert(void 0!==a.pci_bars);var b=a.pci_id;dbg_log("PCI register bdf="+h(b)+" ("+a.name+")",LOG_PCI);dbg_assert(!this.devices[b]);dbg_assert(64<=a.pci_space.length);dbg_assert(b<this.devices.length);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];
if(e){var g=b[d],f=g&1;e.original_bar=g;e.entries=[];if(0!==f)for(dbg_assert(1===f),g&=-2,f=0;f<e.size;f++)e.entries[f]=this.io.ports[g+f]}}return c};
PCI.prototype.set_io_bars=function(a,b,c){var d=a.size;dbg_log("Move io bars: from="+h(b)+" to="+h(c)+" count="+d,LOG_PCI);for(var e=this.io.ports,g=0;g<d;g++){var f=e[b+g];4096<=b+g&&(e[b+g]=this.io.create_empty_entry());f.read8===this.io.empty_port_read8&&f.read16===this.io.empty_port_read16&&f.read32===this.io.empty_port_read32&&f.write8===this.io.empty_port_write&&f.write16===this.io.empty_port_write&&f.write32===this.io.empty_port_write&&dbg_log("Warning: Bad IO bar: Source not mapped, port="+
h(b+g,4),LOG_PCI);f=a.entries[g];var k=e[c+g];dbg_assert(f&&k);4096<=c+g&&(e[c+g]=f);k.read8!==this.io.empty_port_read8&&k.read16!==this.io.empty_port_read16&&k.read32!==this.io.empty_port_read32&&k.write8!==this.io.empty_port_write&&k.write16!==this.io.empty_port_write&&k.write32!==this.io.empty_port_write||dbg_log("Warning: Bad IO bar: Target already mapped, port="+h(c+g,4),LOG_PCI)}};
PCI.prototype.raise_irq=function(a){var b=this.device_spaces[a];dbg_assert(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};PCI.prototype.lower_irq=function(a){var b=this.device_spaces[a];dbg_assert(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+((b[15]>>8&255)+(a>>3&255)-2&3)])};function FloppyController(a,b,c){this.io=a.io;this.cpu=a;this.dma=a.devices.dma;this.bytes_expecting=0;this.receiving_command=new Uint8Array(10);this.receiving_index=0;this.next_command=null;this.response_data=new Uint8Array(10);this.response_length=this.response_index=0;this.fda_image=b;this.fdb_image=c;this.last_head=this.last_cylinder=this.drive=this.status_reg2=this.status_reg1=this.status_reg0=0;this.last_sector=1;this.dor=0;if(b){var d={[163840]:{type:1,tracks:40,sectors:8,heads:1},[184320]:{type:1,
tracks:40,sectors:9,heads:1},[204800]:{type:1,tracks:40,sectors:10,heads:1},[327680]:{type:1,tracks:40,sectors:8,heads:2},[368640]:{type:1,tracks:40,sectors:9,heads:2},[409600]:{type:1,tracks:40,sectors:10,heads:2},[737280]:{type:3,tracks:80,sectors:9,heads:2},[1228800]:{type:2,tracks:80,sectors:15,heads:2},[1474560]:{type:4,tracks:80,sectors:18,heads:2},[1763328]:{type:5,tracks:82,sectors:21,heads:2},[2949120]:{type:5,tracks:80,sectors:36,heads:2},512:{type:1,tracks:1,sectors:1,heads:1}};let e=b.byteLength;
c=d[e];c||(e=1474560<b.byteLength?2949120:1474560,c=d[e],dbg_log("Warning: Unkown floppy size: "+b.byteLength+", assuming "+e));a.devices.rtc.cmos_write(CMOS_FLOPPY_DRIVE_TYPE,c.type<<4);a=c.sectors;b=c.heads;c=c.tracks;this.sectors_per_track=a;this.number_of_heads=b;this.number_of_cylinders=c}else a.devices.rtc.cmos_write(CMOS_FLOPPY_DRIVE_TYPE,64),this.number_of_cylinders=this.number_of_heads=this.sectors_per_track=0;this.io.register_read(1008,this,this.port3F0_read);this.io.register_read(1010,
this,this.port3F2_read);this.io.register_read(1012,this,this.port3F4_read);this.io.register_read(1013,this,this.port3F5_read);this.io.register_read(1015,this,this.port3F7_read);this.io.register_write(1010,this,this.port3F2_write);this.io.register_write(1013,this,this.port3F5_write)}
FloppyController.prototype.get_state=function(){var a=[];a[0]=this.bytes_expecting;a[1]=this.receiving_command;a[2]=this.receiving_index;a[4]=this.response_data;a[5]=this.response_index;a[6]=this.response_length;a[8]=this.status_reg0;a[9]=this.status_reg1;a[10]=this.status_reg2;a[11]=this.drive;a[12]=this.last_cylinder;a[13]=this.last_head;a[14]=this.last_sector;a[15]=this.dor;a[16]=this.sectors_per_track;a[17]=this.number_of_heads;a[18]=this.number_of_cylinders;return a};
FloppyController.prototype.set_state=function(a){this.bytes_expecting=a[0];this.receiving_command=a[1];this.receiving_index=a[2];this.next_command=a[3];this.response_data=a[4];this.response_index=a[5];this.response_length=a[6];this.status_reg0=a[8];this.status_reg1=a[9];this.status_reg2=a[10];this.drive=a[11];this.last_cylinder=a[12];this.last_head=a[13];this.last_sector=a[14];this.dor=a[15];this.sectors_per_track=a[16];this.number_of_heads=a[17];this.number_of_cylinders=a[18]};
FloppyController.prototype.port3F0_read=function(){dbg_log("3F0 read",LOG_FLOPPY);return 0};FloppyController.prototype.port3F4_read=function(){dbg_log("3F4 read",LOG_FLOPPY);var a=128;this.response_index<this.response_length&&(a|=80);0===(this.dor&8)&&(a|=32);return a};FloppyController.prototype.port3F7_read=function(){dbg_log("3F7 read",LOG_FLOPPY);return 0};
FloppyController.prototype.port3F5_read=function(){if(this.response_index<this.response_length)return dbg_log("3F5 read: "+this.response_data[this.response_index],LOG_FLOPPY),this.cpu.device_lower_irq(6),this.response_data[this.response_index++];dbg_log("3F5 read, empty",LOG_FLOPPY);return 255};
FloppyController.prototype.port3F5_write=function(a){if(this.fda_image)if(dbg_log("3F5 write "+h(a),LOG_FLOPPY),0<this.bytes_expecting){if(this.receiving_command[this.receiving_index++]=a,this.bytes_expecting--,0===this.bytes_expecting){if(DEBUG){a="3F5 command received: ";for(var b=0;b<this.receiving_index;b++)a+=h(this.receiving_command[b])+" ";dbg_log(a,LOG_FLOPPY)}this.next_command.call(this,this.receiving_command)}}else{switch(a){case 3:this.next_command=this.fix_drive_data;this.bytes_expecting=
2;break;case 4:this.next_command=this.check_drive_status;this.bytes_expecting=1;break;case 5:case 69:case 197:this.next_command=function(c){this.do_sector(!0,c)};this.bytes_expecting=8;break;case 230:this.next_command=function(c){this.do_sector(!1,c)};this.bytes_expecting=8;break;case 7:this.next_command=this.calibrate;this.bytes_expecting=1;break;case 8:this.check_interrupt_status();break;case 74:this.next_command=this.read_sector_id;this.bytes_expecting=1;break;case 15:this.bytes_expecting=2;this.next_command=
this.seek;break;case 14:dbg_log("dump registers",LOG_FLOPPY);this.response_data[0]=128;this.response_index=0;this.response_length=1;this.bytes_expecting=0;break;default:dbg_assert(!1,"Unimplemented floppy command call "+h(a))}this.receiving_index=0}};FloppyController.prototype.port3F2_read=function(){dbg_log("read 3F2: DOR",LOG_FLOPPY);return this.dor};
FloppyController.prototype.port3F2_write=function(a){4===(a&4)&&0===(this.dor&4)&&this.cpu.device_raise_irq(6);dbg_log("start motors: "+h(a>>4),LOG_FLOPPY);dbg_log("enable dma: "+!!(a&8),LOG_FLOPPY);dbg_log("reset fdc: "+!!(a&4),LOG_FLOPPY);dbg_log("drive select: "+(a&3),LOG_FLOPPY);dbg_log("DOR = "+h(a),LOG_FLOPPY);this.dor=a};FloppyController.prototype.check_drive_status=function(a){dbg_log("check drive status",LOG_FLOPPY);this.response_index=0;this.response_length=1;this.response_data[0]=32};
FloppyController.prototype.seek=function(a){dbg_log("seek",LOG_FLOPPY);dbg_assert(0===(a[0]&3),"Unhandled seek drive");this.last_cylinder=a[1];this.last_head=a[0]>>2&1;this.raise_irq()};FloppyController.prototype.calibrate=function(a){dbg_log("floppy calibrate",LOG_FLOPPY);this.raise_irq()};FloppyController.prototype.check_interrupt_status=function(){dbg_log("floppy check interrupt status",LOG_FLOPPY);this.response_index=0;this.response_length=2;this.response_data[0]=32;this.response_data[1]=this.last_cylinder};
FloppyController.prototype.do_sector=function(a,b){var c=b[2],d=b[1],e=b[3],g=128<<b[4],f=b[5]-b[3]+1,k=((c+this.number_of_heads*d)*this.sectors_per_track+e-1)*g;dbg_log("Floppy "+(a?"Write":"Read"),LOG_FLOPPY);dbg_log("from "+h(k)+" length "+h(f*g),LOG_FLOPPY);dbg_log(d+" / "+c+" / "+e,LOG_FLOPPY);b[4]||dbg_log("FDC: sector count is zero, use data length instead",LOG_FLOPPY);this.fda_image&&(a?this.dma.do_write(this.fda_image,k,f*g,2,this.done.bind(this,b,d,c,e)):this.dma.do_read(this.fda_image,
k,f*g,2,this.done.bind(this,b,d,c,e)))};FloppyController.prototype.done=function(a,b,c,d,e){e||(d++,d>this.sectors_per_track&&(d=1,c++,c>=this.number_of_heads&&(c=0,b++)),this.last_cylinder=b,this.last_head=c,this.last_sector=d,this.response_index=0,this.response_length=7,this.response_data[0]=c<<2|32,this.response_data[1]=0,this.response_data[2]=0,this.response_data[3]=b,this.response_data[4]=c,this.response_data[5]=d,this.response_data[6]=a[4],this.raise_irq())};
FloppyController.prototype.fix_drive_data=function(a){dbg_log("floppy fix drive data "+a,LOG_FLOPPY)};FloppyController.prototype.read_sector_id=function(a){dbg_log("floppy read sector id "+a,LOG_FLOPPY);this.response_index=0;this.response_length=7;this.response_data[0]=0;this.response_data[1]=0;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=0;this.response_data[5]=0;this.response_data[6]=0;this.raise_irq()};FloppyController.prototype.raise_irq=function(){this.dor&8&&this.cpu.device_raise_irq(6)};CPU.prototype.mmap_read8=function(a){a=this.memory_map_read8[a>>>MMAP_BLOCK_BITS](a);dbg_assert(0<=a&&255>=a);return a};CPU.prototype.mmap_write8=function(a,b){dbg_assert(0<=b&&255>=b);this.memory_map_write8[a>>>MMAP_BLOCK_BITS](a,b)};CPU.prototype.mmap_read16=function(a){var b=this.memory_map_read8[a>>>MMAP_BLOCK_BITS];a=b(a)|b(a+1|0)<<8;dbg_assert(0<=a&&65535>=a);return a};
CPU.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>MMAP_BLOCK_BITS];dbg_assert(0<=b&&65535>=b);c(a,b&255);c(a+1|0,b>>8)};CPU.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>MMAP_BLOCK_BITS](a)};CPU.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>MMAP_BLOCK_BITS](a,b)};CPU.prototype.mmap_write64=function(a,b,c){var d=a>>>MMAP_BLOCK_BITS;dbg_assert(d===a+7>>>MMAP_BLOCK_BITS);d=this.memory_map_write32[d];d(a,b);d(a+4,c)};
CPU.prototype.mmap_write128=function(a,b,c,d,e){var g=a>>>MMAP_BLOCK_BITS;dbg_assert(g===a+12>>>MMAP_BLOCK_BITS);g=this.memory_map_write32[g];g(a,b);g(a+4,c);g(a+8,d);g(a+12,e)};CPU.prototype.write_blob=function(a,b){dbg_assert(a&&0<=a.length);a.length&&(dbg_assert(!this.in_mapped_range(b)),dbg_assert(!this.in_mapped_range(b+a.length-1)),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))};
CPU.prototype.read_blob=function(a,b){b&&(dbg_assert(!this.in_mapped_range(a)),dbg_assert(!this.in_mapped_range(a+b-1)));return this.mem8.subarray(a,a+b)};function DMA(a){this.cpu=a;this.channel_page=new Uint8Array(8);this.channel_pagehi=new Uint8Array(8);this.channel_addr=new Uint16Array(8);this.channel_addr_init=new Uint16Array(8);this.channel_count=new Uint16Array(8);this.channel_count_init=new Uint16Array(8);this.channel_mask=new Uint8Array(8);this.channel_mode=new Uint8Array(8);this.unmask_listeners=[];this.lsb_msb_flipflop=0;a=a.io;a.register_write(0,this,this.port_addr_write.bind(this,0));a.register_write(2,this,this.port_addr_write.bind(this,
1));a.register_write(4,this,this.port_addr_write.bind(this,2));a.register_write(6,this,this.port_addr_write.bind(this,3));a.register_write(1,this,this.port_count_write.bind(this,0));a.register_write(3,this,this.port_count_write.bind(this,1));a.register_write(5,this,this.port_count_write.bind(this,2));a.register_write(7,this,this.port_count_write.bind(this,3));a.register_read(0,this,this.port_addr_read.bind(this,0));a.register_read(2,this,this.port_addr_read.bind(this,1));a.register_read(4,this,this.port_addr_read.bind(this,
2));a.register_read(6,this,this.port_addr_read.bind(this,3));a.register_read(1,this,this.port_count_read.bind(this,0));a.register_read(3,this,this.port_count_read.bind(this,1));a.register_read(5,this,this.port_count_read.bind(this,2));a.register_read(7,this,this.port_count_read.bind(this,3));a.register_write(192,this,this.port_addr_write.bind(this,4));a.register_write(196,this,this.port_addr_write.bind(this,5));a.register_write(200,this,this.port_addr_write.bind(this,6));a.register_write(204,this,
this.port_addr_write.bind(this,7));a.register_write(194,this,this.port_count_write.bind(this,4));a.register_write(198,this,this.port_count_write.bind(this,5));a.register_write(202,this,this.port_count_write.bind(this,6));a.register_write(206,this,this.port_count_write.bind(this,7));a.register_read(192,this,this.port_addr_read.bind(this,4));a.register_read(196,this,this.port_addr_read.bind(this,5));a.register_read(200,this,this.port_addr_read.bind(this,6));a.register_read(204,this,this.port_addr_read.bind(this,
7));a.register_read(194,this,this.port_count_read.bind(this,4));a.register_read(198,this,this.port_count_read.bind(this,5));a.register_read(202,this,this.port_count_read.bind(this,6));a.register_read(206,this,this.port_count_read.bind(this,7));a.register_write(135,this,this.port_page_write.bind(this,0));a.register_write(131,this,this.port_page_write.bind(this,1));a.register_write(129,this,this.port_page_write.bind(this,2));a.register_write(130,this,this.port_page_write.bind(this,3));a.register_write(143,
this,this.port_page_write.bind(this,4));a.register_write(139,this,this.port_page_write.bind(this,5));a.register_write(137,this,this.port_page_write.bind(this,6));a.register_write(138,this,this.port_page_write.bind(this,7));a.register_read(135,this,this.port_page_read.bind(this,0));a.register_read(131,this,this.port_page_read.bind(this,1));a.register_read(129,this,this.port_page_read.bind(this,2));a.register_read(130,this,this.port_page_read.bind(this,3));a.register_read(143,this,this.port_page_read.bind(this,
4));a.register_read(139,this,this.port_page_read.bind(this,5));a.register_read(137,this,this.port_page_read.bind(this,6));a.register_read(138,this,this.port_page_read.bind(this,7));a.register_write(1159,this,this.port_pagehi_write.bind(this,0));a.register_write(1155,this,this.port_pagehi_write.bind(this,1));a.register_write(1153,this,this.port_pagehi_write.bind(this,2));a.register_write(1154,this,this.port_pagehi_write.bind(this,3));a.register_write(1163,this,this.port_pagehi_write.bind(this,5));
a.register_write(1161,this,this.port_pagehi_write.bind(this,6));a.register_write(1162,this,this.port_pagehi_write.bind(this,7));a.register_read(1159,this,this.port_pagehi_read.bind(this,0));a.register_read(1155,this,this.port_pagehi_read.bind(this,1));a.register_read(1153,this,this.port_pagehi_read.bind(this,2));a.register_read(1154,this,this.port_pagehi_read.bind(this,3));a.register_read(1163,this,this.port_pagehi_read.bind(this,5));a.register_read(1161,this,this.port_pagehi_read.bind(this,6));a.register_read(1162,
this,this.port_pagehi_read.bind(this,7));a.register_write(10,this,this.port_singlemask_write.bind(this,0));a.register_write(212,this,this.port_singlemask_write.bind(this,4));a.register_write(15,this,this.port_multimask_write.bind(this,0));a.register_write(222,this,this.port_multimask_write.bind(this,4));a.register_read(15,this,this.port_multimask_read.bind(this,0));a.register_read(222,this,this.port_multimask_read.bind(this,4));a.register_write(11,this,this.port_mode_write.bind(this,0));a.register_write(214,
this,this.port_mode_write.bind(this,4));a.register_write(12,this,this.portC_write);a.register_write(216,this,this.portC_write)}DMA.prototype.get_state=function(){return[this.channel_page,this.channel_pagehi,this.channel_addr,this.channel_addr_init,this.channel_count,this.channel_count_init,this.channel_mask,this.channel_mode,this.lsb_msb_flipflop]};
DMA.prototype.set_state=function(a){this.channel_page=a[0];this.channel_pagehi=a[1];this.channel_addr=a[2];this.channel_addr_init=a[3];this.channel_count=a[4];this.channel_count_init=a[5];this.channel_mask=a[6];this.channel_mode=a[7];this.lsb_msb_flipflop=a[8]};DMA.prototype.port_count_write=function(a,b){dbg_log("count write ["+a+"] = "+h(b),LOG_DMA);this.channel_count[a]=this.flipflop_get(this.channel_count[a],b,!1);this.channel_count_init[a]=this.flipflop_get(this.channel_count_init[a],b,!0)};
DMA.prototype.port_count_read=function(a){dbg_log("count read ["+a+"] -> "+h(this.channel_count[a]),LOG_DMA);return this.flipflop_read(this.channel_count[a])};DMA.prototype.port_addr_write=function(a,b){dbg_log("addr write ["+a+"] = "+h(b),LOG_DMA);this.channel_addr[a]=this.flipflop_get(this.channel_addr[a],b,!1);this.channel_addr_init[a]=this.flipflop_get(this.channel_addr_init[a],b,!0)};DMA.prototype.port_addr_read=function(a){dbg_log("addr read ["+a+"] -> "+h(this.channel_addr[a]),LOG_DMA);return this.flipflop_read(this.channel_addr[a])};
DMA.prototype.port_pagehi_write=function(a,b){dbg_log("pagehi write ["+a+"] = "+h(b),LOG_DMA);this.channel_pagehi[a]=b};DMA.prototype.port_pagehi_read=function(a){dbg_log("pagehi read ["+a+"]",LOG_DMA);return this.channel_pagehi[a]};DMA.prototype.port_page_write=function(a,b){dbg_log("page write ["+a+"] = "+h(b),LOG_DMA);this.channel_page[a]=b};DMA.prototype.port_page_read=function(a){dbg_log("page read ["+a+"]",LOG_DMA);return this.channel_page[a]};
DMA.prototype.port_singlemask_write=function(a,b){a=(b&3)+a;b=b&4?1:0;dbg_log("singlechannel mask write ["+a+"] = "+b,LOG_DMA);this.update_mask(a,b)};DMA.prototype.port_multimask_write=function(a,b){dbg_log("multichannel mask write: "+h(b),LOG_DMA);for(var c=0;4>c;c++)this.update_mask(a+c,b&1<<c)};
DMA.prototype.port_multimask_read=function(a){var b=0|this.channel_mask[a+0];b|=this.channel_mask[a+1]<<1;b|=this.channel_mask[a+2]<<2;b|=this.channel_mask[a+3]<<3;dbg_log("multichannel mask read: "+h(b),LOG_DMA);return b};DMA.prototype.port_mode_write=function(a,b){a=(b&3)+a;dbg_log("mode write ["+a+"] = "+h(b),LOG_DMA);this.channel_mode[a]=b};DMA.prototype.portC_write=function(a){dbg_log("flipflop reset",LOG_DMA);this.lsb_msb_flipflop=0};
DMA.prototype.on_unmask=function(a,b){this.unmask_listeners.push({fn:a,this_value:b})};DMA.prototype.update_mask=function(a,b){if(this.channel_mask[a]!==b&&(this.channel_mask[a]=b,!b))for(dbg_log("firing on_unmask("+a+")",LOG_DMA),b=0;b<this.unmask_listeners.length;b++)this.unmask_listeners[b].fn.call(this.unmask_listeners[b].this_value,a)};
DMA.prototype.do_read=function(a,b,c,d,e){var g=this.count_get_8bit(d),f=this.address_get_8bit(d);dbg_log("DMA write channel "+d,LOG_DMA);dbg_log("to "+h(f)+" len "+h(g),LOG_DMA);c<g&&dbg_log("DMA should read more than provided: "+h(c)+" "+h(g),LOG_DMA);if(b+g>a.byteLength)dbg_log("DMA read outside of buffer",LOG_DMA),e(!0);else{var k=this.cpu;this.channel_addr[d]+=g;a.get(b,g,function(m){k.write_blob(m,f);e(!1)})}};
DMA.prototype.do_write=function(a,b,c,d,e){var g=this.channel_count[d]+1&65535,f=5<=d?2:1,k=g*f,m=this.address_get_8bit(d),l=!1,n=!1,p=this.channel_mode[d]&16;dbg_log("DMA write channel "+d,LOG_DMA);dbg_log("to "+h(m)+" len "+h(k),LOG_DMA);c<k?(dbg_log("DMA should read more than provided",LOG_DMA),g=Math.floor(c/f),k=g*f,l=!0):c>k&&(dbg_log("DMA attempted to read more than provided",LOG_DMA),n=!0);b+k>a.byteLength?(dbg_log("DMA write outside of buffer",LOG_DMA),e(!0)):(this.channel_addr[d]+=g,this.channel_count[d]-=
g,!l&&p&&(dbg_log("DMA autoinit",LOG_DMA),this.channel_addr[d]=this.channel_addr_init[d],this.channel_count[d]=this.channel_count_init[d]),a.set(b,this.cpu.mem8.subarray(m,m+k),()=>{n&&p?(dbg_log("DMA continuing from start",LOG_DMA),this.do_write(a,b+k,c-k,d,e)):e(!1)}))};DMA.prototype.address_get_8bit=function(a){var b=this.channel_addr[a];5<=a&&(b<<=1);b=b&65535|this.channel_page[a]<<16;return b|=this.channel_pagehi[a]<<24};
DMA.prototype.count_get_8bit=function(a){var b=this.channel_count[a]+1;5<=a&&(b*=2);return b};DMA.prototype.flipflop_get=function(a,b,c){c||(this.lsb_msb_flipflop^=1);return this.lsb_msb_flipflop?a&-256|b:a&-65281|b<<8};DMA.prototype.flipflop_read=function(a){return(this.lsb_msb_flipflop^=1)?a&255:a>>8&255};var OSCILLATOR_FREQ=1193.1816666;
function PIT(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=v86.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,
c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,
function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}PIT.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};
PIT.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];this.counter_read_mode=a[3];this.counter_latch=a[4];this.counter_latch_value=a[5];this.counter_reload=a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]};
PIT.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,dbg_log("pit interrupt. new value: "+this.counter_start_value[0],LOG_PIT),this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor((a-this.counter_start_time[0])*OSCILLATOR_FREQ))/
OSCILLATOR_FREQ));return c};PIT.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;var c=b-this.counter_start_time[a],d=Math.floor(c*OSCILLATOR_FREQ);b=this.counter_start_value[a]-d;dbg_log("diff="+c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],LOG_PIT);c=this.counter_reload[a];b>=c?(dbg_log("Warning: Counter"+a+" value "+b+" is larger than reload "+c,LOG_PIT),b%=c):0>b&&(b=b%c+c);return b};
PIT.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(dbg_log("Warning: PIT timer difference is negative, resetting (timer "+a+")"),!0):this.counter_start_value[a]<Math.floor(b*OSCILLATOR_FREQ)};
PIT.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,v86.microtick());return b?a&255:a>>8};
PIT.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=v86.microtick(),dbg_log("counter"+a+" reload="+h(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/OSCILLATOR_FREQ+"ms",
LOG_PIT));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};
PIT.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,d=a>>6&3;a=a>>4&3;1===d&&dbg_log("Unimplemented timer1",LOG_PIT);3===d?dbg_log("Unimplemented read back",LOG_PIT):0===a?(this.counter_latch[d]=2,b=this.get_counter_value(d,v86.microtick()),dbg_log("latch: "+b,LOG_PIT),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),dbg_log("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,LOG_PIT),this.counter_next_low[d]=1===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&dbg_log("Unimplemented counter mode: "+
h(b),LOG_PIT),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]]))};PIT.prototype.dump=function(){const a=this.counter_reload[0];dbg_log("counter0 ticks every "+(a||65536)/OSCILLATOR_FREQ+"ms (reload="+a+")")};var VGA_BANK_SIZE=65536,MAX_XRES=2560,MAX_YRES=1600,MAX_BPP=32,VGA_LFB_ADDRESS=3758096384,VGA_PIXEL_BUFFER_SIZE=8*VGA_BANK_SIZE,VGA_MIN_MEMORY_SIZE=4*VGA_BANK_SIZE,VGA_HOST_MEMORY_SPACE_START=Uint32Array.from([655360,655360,720896,753664]),VGA_HOST_MEMORY_SPACE_SIZE=Uint32Array.from([131072,65536,32768,32768]);
function VGAScreen(a,b,c){this.cpu=a;this.bus=b;this.vga_memory_size=c;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_is_linear=!0;this.graphical_mode=!1;setTimeout(()=>{b.send("screen-set-mode",this.graphical_mode)},0);this.vga256_palette=new Int32Array(256);this.svga_height=this.svga_width=this.latch_dword=0;this.svga_enabled=!1;this.svga_bpp=32;this.svga_offset=this.svga_bank_offset=0;this.pci_space=[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,8,VGA_LFB_ADDRESS>>>8,VGA_LFB_ADDRESS>>>16,VGA_LFB_ADDRESS>>>24,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:c}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.stats={is_graphical:!1,res_x:0,res_y:0,bpp:0};this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=this.horizontal_panning=this.color_plane_enable=
this.attribute_mode=0;this.sequencer_index=-1;this.plane_write_bm=15;this.clocking_mode=this.sequencer_memory_mode=0;this.graphics_index=-1;this.planar_rotate_reg=this.planar_mode=this.plane_read=0;this.planar_bitmap=255;this.max_scan_line=this.color_dont_care=this.color_compare=this.miscellaneous_graphics_register=this.planar_setreset_enable=this.planar_setreset=0;this.port_3DA_value=this.miscellaneous_output_register=255;c=a.io;c.register_write(960,this,this.port3C0_write);c.register_read(960,this,
this.port3C0_read,this.port3C0_read16);c.register_read(961,this,this.port3C1_read);c.register_write(962,this,this.port3C2_write);c.register_write_consecutive(964,this,this.port3C4_write,this.port3C5_write);c.register_read(964,this,this.port3C4_read);c.register_read(965,this,this.port3C5_read);c.register_write_consecutive(974,this,this.port3CE_write,this.port3CF_write);c.register_read(974,this,this.port3CE_read);c.register_read(975,this,this.port3CF_read);c.register_read(966,this,this.port3C6_read);
c.register_write(966,this,this.port3C6_write);c.register_write(967,this,this.port3C7_write);c.register_read(967,this,this.port3C7_read);c.register_write(968,this,this.port3C8_write);c.register_read(968,this,this.port3C8_read);c.register_write(969,this,this.port3C9_write);c.register_read(969,this,this.port3C9_read);c.register_read(972,this,this.port3CC_read);c.register_write_consecutive(980,this,this.port3D4_write,this.port3D5_write);c.register_read(980,this,this.port3D4_read);c.register_read(981,
this,this.port3D5_read,()=>{dbg_log("Warning: 16-bit read from 3D5",LOG_VGA);return this.port3D5_read()});c.register_read(970,this,function(){dbg_log("3CA read",LOG_VGA);return 0});c.register_read(986,this,this.port3DA_read);c.register_read(954,this,this.port3DA_read);this.dispi_index=-1;this.dispi_enable_value=0;c.register_write(462,this,void 0,this.port1CE_write);c.register_write(463,this,void 0,this.port1CF_write);c.register_read(463,this,void 0,this.port1CF_read);void 0===this.vga_memory_size||
this.vga_memory_size<VGA_MIN_MEMORY_SIZE?(this.vga_memory_size=VGA_MIN_MEMORY_SIZE,dbg_log("vga memory size rounded up to "+this.vga_memory_size,LOG_VGA)):this.vga_memory_size&VGA_BANK_SIZE-1&&(this.vga_memory_size|=VGA_BANK_SIZE-1,this.vga_memory_size++);const d=a.svga_allocate_memory(this.vga_memory_size);this.svga_memory=v86util.view(Uint8Array,a.wasm_memory,d,this.vga_memory_size);this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=
0;this.image_data=null;b.register("screen-fill-buffer",function(){this.screen_fill_buffer()},this);this.vga_memory=new Uint8Array(4*VGA_BANK_SIZE);this.plane0=new Uint8Array(this.vga_memory.buffer,0*VGA_BANK_SIZE,VGA_BANK_SIZE);this.plane1=new Uint8Array(this.vga_memory.buffer,1*VGA_BANK_SIZE,VGA_BANK_SIZE);this.plane2=new Uint8Array(this.vga_memory.buffer,2*VGA_BANK_SIZE,VGA_BANK_SIZE);this.plane3=new Uint8Array(this.vga_memory.buffer,3*VGA_BANK_SIZE,VGA_BANK_SIZE);this.pixel_buffer=new Uint8Array(VGA_PIXEL_BUFFER_SIZE);
var e=this;c.mmap_register(655360,131072,function(g){return e.vga_memory_read(g)},function(g,f){e.vga_memory_write(g,f)});a.devices.pci.register_device(this)}
VGAScreen.prototype.get_state=function(){var a=[];a[0]=this.vga_memory_size;a[1]=this.cursor_address;a[2]=this.cursor_scanline_start;a[3]=this.cursor_scanline_end;a[4]=this.max_cols;a[5]=this.max_rows;a[6]=this.vga_memory;a[7]=this.dac_state;a[8]=this.start_address;a[9]=this.graphical_mode;a[10]=this.vga256_palette;a[11]=this.latch_dword;a[12]=this.color_compare;a[13]=this.color_dont_care;a[14]=this.miscellaneous_graphics_register;a[15]=this.svga_width;a[16]=this.svga_height;a[17]=this.crtc_mode;
a[18]=this.svga_enabled;a[19]=this.svga_bpp;a[20]=this.svga_bank_offset;a[21]=this.svga_offset;a[22]=this.index_crtc;a[23]=this.dac_color_index_write;a[24]=this.dac_color_index_read;a[25]=this.dac_map;a[26]=this.sequencer_index;a[27]=this.plane_write_bm;a[28]=this.sequencer_memory_mode;a[29]=this.graphics_index;a[30]=this.plane_read;a[31]=this.planar_mode;a[32]=this.planar_rotate_reg;a[33]=this.planar_bitmap;a[34]=this.max_scan_line;a[35]=this.miscellaneous_output_register;a[36]=this.port_3DA_value;
a[37]=this.dispi_index;a[38]=this.dispi_enable_value;a[39]=this.svga_memory;a[40]=this.graphical_mode_is_linear;a[41]=this.attribute_controller_index;a[42]=this.offset_register;a[43]=this.planar_setreset;a[44]=this.planar_setreset_enable;a[45]=this.start_address_latched;a[46]=this.crtc;a[47]=this.horizontal_display_enable_end;a[48]=this.horizontal_blank_start;a[49]=this.vertical_display_enable_end;a[50]=this.vertical_blank_start;a[51]=this.underline_location_register;a[52]=this.preset_row_scan;a[53]=
this.offset_register;a[54]=this.palette_source;a[55]=this.attribute_mode;a[56]=this.color_plane_enable;a[57]=this.horizontal_panning;a[58]=this.color_select;a[59]=this.clocking_mode;a[60]=this.line_compare;a[61]=this.pixel_buffer;a[62]=this.dac_mask;return a};
VGAScreen.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=a[2];this.cursor_scanline_end=a[3];this.max_cols=a[4];this.max_rows=a[5];a[6]&&this.vga_memory.set(a[6]);this.dac_state=a[7];this.start_address=a[8];this.graphical_mode=a[9];this.vga256_palette=a[10];this.latch_dword=a[11];this.color_compare=a[12];this.color_dont_care=a[13];this.miscellaneous_graphics_register=a[14];this.svga_width=a[15];this.svga_height=a[16];this.crtc_mode=a[17];
this.svga_enabled=a[18];this.svga_bpp=a[19];this.svga_bank_offset=a[20];this.svga_offset=a[21];this.index_crtc=a[22];this.dac_color_index_write=a[23];this.dac_color_index_read=a[24];this.dac_map=a[25];this.sequencer_index=a[26];this.plane_write_bm=a[27];this.sequencer_memory_mode=a[28];this.graphics_index=a[29];this.plane_read=a[30];this.planar_mode=a[31];this.planar_rotate_reg=a[32];this.planar_bitmap=a[33];this.max_scan_line=a[34];this.miscellaneous_output_register=a[35];this.port_3DA_value=a[36];
this.dispi_index=a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.graphical_mode_is_linear=a[40];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.bus.send("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_bpp,this.svga_width,
this.svga_height),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_size_text(this.max_cols,this.max_rows),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};
VGAScreen.prototype.vga_memory_read=function(a){if(this.svga_enabled&&this.graphical_mode_is_linear)return this.cpu.read8((a-655360|this.svga_bank_offset)+VGA_LFB_ADDRESS|0);var b=this.miscellaneous_graphics_register>>2&3;a-=VGA_HOST_MEMORY_SPACE_START[b];if(0>a||a>=VGA_HOST_MEMORY_SPACE_SIZE[b])return dbg_log("vga read outside memory space: addr:"+h(a),LOG_VGA),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=0;return this.vga_memory[b<<16|a]};
VGAScreen.prototype.vga_memory_write=function(a,b){if(this.svga_enabled&&this.graphical_mode&&this.graphical_mode_is_linear)this.cpu.write8((a-655360|this.svga_bank_offset)+VGA_LFB_ADDRESS|0,b);else{var c=this.miscellaneous_graphics_register>>2&3;a-=VGA_HOST_MEMORY_SPACE_START[c];0>a||a>=VGA_HOST_MEMORY_SPACE_SIZE[c]?dbg_log("vga write outside memory space: addr:"+h(a)+", value:"+h(b),LOG_VGA):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3&&this.vga_memory_write_text_mode(a,
b)}};
VGAScreen.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),g=this.apply_expand(this.planar_setreset_enable);switch(c){case 0:b=this.apply_rotate(b);var f=this.apply_feed(b);f=this.apply_setreset(f,g);f=this.apply_logical(f,this.latch_dword);f=this.apply_bitmask(f,d);break;case 1:f=this.latch_dword;break;case 2:f=this.apply_expand(b);f=this.apply_logical(f,this.latch_dword);f=this.apply_bitmask(f,d);
break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),f=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]=f>>0&255);b&2&&(this.plane1[a]=f>>8&255);b&4&&(this.plane2[a]=f>>16&255);b&8&&(this.plane3[a]=f>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};VGAScreen.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};
VGAScreen.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};VGAScreen.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};VGAScreen.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};VGAScreen.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};
VGAScreen.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};VGAScreen.prototype.text_mode_redraw=function(){for(var a=this.start_address<<1,b,c,d=0;d<this.max_rows;d++)for(var e=0;e<this.max_cols;e++)b=this.vga_memory[a],c=this.vga_memory[a|1],this.bus.send("screen-put-char",[d,e,b,this.vga256_palette[this.dac_mask&this.dac_map[c>>4&15]],this.vga256_palette[this.dac_mask&this.dac_map[c&15]]]),a+=2};
VGAScreen.prototype.vga_memory_write_text_mode=function(a,b){var c=(a>>1)-this.start_address,d=c/this.max_cols|0;c%=this.max_cols;if(a&1){var e=b;var g=this.vga_memory[a&-2]}else g=b,e=this.vga_memory[a|1];this.bus.send("screen-put-char",[d,c,g,this.vga256_palette[this.dac_mask&this.dac_map[e>>4&15]],this.vga256_palette[this.dac_mask&this.dac_map[e&15]]]);this.vga_memory[a]=b};
VGAScreen.prototype.update_cursor=function(){var a=(this.cursor_address-this.start_address)/this.max_cols|0,b=(this.cursor_address-this.start_address)%this.max_cols;a=Math.min(this.max_rows-1,a);this.bus.send("screen-update-cursor",[a,b])};VGAScreen.prototype.complete_redraw=function(){dbg_log("complete redraw",LOG_VGA);this.graphical_mode?this.svga_enabled?this.cpu.svga_mark_dirty():(this.diff_addr_min=0,this.diff_addr_max=VGA_PIXEL_BUFFER_SIZE):this.text_mode_redraw()};
VGAScreen.prototype.complete_replot=function(){dbg_log("complete replot",LOG_VGA);this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=VGA_PIXEL_BUFFER_SIZE,this.complete_redraw())};VGAScreen.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&(this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=b)};
VGAScreen.prototype.partial_replot=function(a,b){a<this.diff_plot_min&&(this.diff_plot_min=a);b>this.diff_plot_max&&(this.diff_plot_max=b);this.partial_redraw(a,b)};VGAScreen.prototype.reset_diffs=function(){this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0};VGAScreen.prototype.destroy=function(){};
VGAScreen.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};VGAScreen.prototype.vga_addr_shift_count=function(){var a=128+(~this.underline_location_register&this.crtc_mode&64);a-=this.underline_location_register&64;a-=this.attribute_mode&64;return a>>>6};
VGAScreen.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~this.crtc_mode&3){var c=a-this.start_address;c&=this.crtc_mode<<13|-24577;c<<=b;var d=c/this.virtual_width|0;c%=this.virtual_width;switch(this.crtc_mode&3){case 2:d=d<<1|a>>13&1;break;case 1:d=d<<1|a>>14&1;break;case 0:d=d<<2|a>>13&3}return d*this.virtual_width+c+(this.start_address<<b)}return a<<b};
VGAScreen.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};VGAScreen.prototype.set_size_text=function(a,b){this.max_cols=a;this.max_rows=b;this.bus.send("screen-set-size-text",[a,b])};
VGAScreen.prototype.set_size_graphical=function(a,b,c,d,e){if(!this.stats.is_graphical||this.stats.bpp!==c||this.screen_width!==a||this.screen_height!==b||this.virtual_width!==d||this.virtual_height!==e){this.screen_width=a;this.screen_height=b;this.virtual_width=d;this.virtual_height=e;this.stats.bpp=c;this.stats.is_graphical=!0;this.stats.res_x=a;this.stats.res_y=b;if("undefined"!==typeof ImageData){const g=d*e,f=this.cpu.svga_allocate_dest_buffer(g)>>>0;this.dest_buffet_offset=f;this.image_data=
new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,f,4*g),d,e);this.cpu.svga_mark_dirty()}this.bus.send("screen-set-size-graphical",[a,b,d,e,c])}};
VGAScreen.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4;this.attribute_mode&64&&(a>>>=1,c>>>=1);b=this.scan_line_to_screen_row(b);var d=Math.ceil(VGA_HOST_MEMORY_SPACE_SIZE[0]/this.vga_bytes_per_line());this.set_size_graphical(a,b,8,c,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)}};
VGAScreen.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.bus.send("screen-clear");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 g=this.screen_height-d;this.layers=[];e=-e;for(var f=0;e<this.screen_width;e+=this.virtual_width,f++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+f,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(f=0;e<this.screen_width;e+=this.virtual_width,f++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:f,
buffer_width:this.virtual_width,buffer_height:g})}};VGAScreen.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};VGAScreen.prototype.update_cursor_scanline=function(){this.bus.send("screen-update-cursor-scanline",[this.cursor_scanline_start,this.cursor_scanline_end])};
VGAScreen.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)dbg_log("attribute controller index register: "+h(a),LOG_VGA),this.attribute_controller_index=a&31,dbg_log("attribute actual index: "+h(this.attribute_controller_index),LOG_VGA),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)dbg_log("internal palette: "+h(this.attribute_controller_index)+" -> "+h(a),LOG_VGA),this.dac_map[this.attribute_controller_index]=
a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:dbg_log("3C0 / attribute mode control: "+h(a),LOG_VGA);if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;var c=0<(a&1);this.svga_enabled||this.graphical_mode===c||(this.graphical_mode=c,this.bus.send("screen-set-mode",this.graphical_mode));(b^a)&64&&this.complete_replot();this.update_vga_size();this.complete_redraw()}break;case 18:dbg_log("3C0 / color plane enable: "+h(a),
LOG_VGA);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:dbg_log("3C0 / horizontal panning: "+h(a),LOG_VGA);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:dbg_log("3C0 / color select: "+h(a),LOG_VGA);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:dbg_log("3C0 / attribute controller write "+h(this.attribute_controller_index)+": "+h(a),LOG_VGA)}this.attribute_controller_index=
-1}};VGAScreen.prototype.port3C0_read=function(){dbg_log("3C0 read",LOG_VGA);return this.attribute_controller_index|this.palette_source};VGAScreen.prototype.port3C0_read16=function(){dbg_log("3C0 read16",LOG_VGA);return this.port3C0_read()&255|this.port3C1_read()<<8&65280};
VGAScreen.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return dbg_log("3C1 / internal palette read: "+h(this.attribute_controller_index)+" -> "+h(this.dac_map[this.attribute_controller_index]),LOG_VGA),this.dac_map[this.attribute_controller_index]&255;switch(this.attribute_controller_index){case 16:return dbg_log("3C1 / attribute mode read: "+h(this.attribute_mode),LOG_VGA),this.attribute_mode;case 18:return dbg_log("3C1 / color plane enable read: "+h(this.color_plane_enable),
LOG_VGA),this.color_plane_enable;case 19:return dbg_log("3C1 / horizontal panning read: "+h(this.horizontal_panning),LOG_VGA),this.horizontal_panning;case 20:return dbg_log("3C1 / color select read: "+h(this.color_select),LOG_VGA),this.color_select;default:dbg_log("3C1 / attribute controller read "+h(this.attribute_controller_index),LOG_VGA)}return 255};VGAScreen.prototype.port3C2_write=function(a){dbg_log("3C2 / miscellaneous output register = "+h(a),LOG_VGA);this.miscellaneous_output_register=a};
VGAScreen.prototype.port3C4_write=function(a){this.sequencer_index=a};VGAScreen.prototype.port3C4_read=function(){return this.sequencer_index};
VGAScreen.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:dbg_log("clocking mode: "+h(a),LOG_VGA);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();break;case 2:dbg_log("plane write mask: "+h(a),LOG_VGA);this.plane_write_bm=a;break;case 4:dbg_log("sequencer memory mode: "+h(a),LOG_VGA);this.sequencer_memory_mode=a;break;default:dbg_log("3C5 / sequencer write "+h(this.sequencer_index)+": "+h(a),LOG_VGA)}};
VGAScreen.prototype.port3C5_read=function(){dbg_log("3C5 / sequencer read "+h(this.sequencer_index),LOG_VGA);switch(this.sequencer_index){case 1:return this.clocking_mode;case 2:return this.plane_write_bm;case 4:return this.sequencer_memory_mode;case 6:return 18}return 0};VGAScreen.prototype.port3C6_write=function(a){this.dac_mask=a};VGAScreen.prototype.port3C6_read=function(){return this.dac_mask};
VGAScreen.prototype.port3C7_write=function(a){dbg_log("3C7 write: "+h(a),LOG_VGA);this.dac_color_index_read=3*a;this.dac_state&=0};VGAScreen.prototype.port3C7_read=function(){return this.dac_state};VGAScreen.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};VGAScreen.prototype.port3C8_read=function(){return this.dac_color_index_write/3&255};
VGAScreen.prototype.port3C9_write=function(a){var b=this.dac_color_index_write/3|0,c=this.dac_color_index_write%3,d=this.vga256_palette[b];if(0===(this.dispi_enable_value&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}0===c?d=d&-16711681|a<<16:1===c?d=d&-65281|a<<8:(d=d&-256|a,dbg_log("dac set color, index="+h(b)+" value="+h(d),LOG_VGA));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++};
VGAScreen.prototype.port3C9_read=function(){dbg_log("3C9 read",LOG_VGA);var a=this.vga256_palette[this.dac_color_index_read/3|0]>>8*(2-this.dac_color_index_read%3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};VGAScreen.prototype.port3CC_read=function(){dbg_log("3CC read",LOG_VGA);return this.miscellaneous_output_register};VGAScreen.prototype.port3CE_write=function(a){this.graphics_index=a};VGAScreen.prototype.port3CE_read=function(){return this.graphics_index};
VGAScreen.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;dbg_log("plane set/reset: "+h(a),LOG_VGA);break;case 1:this.planar_setreset_enable=a;dbg_log("plane set/reset enable: "+h(a),LOG_VGA);break;case 2:this.color_compare=a;dbg_log("color compare: "+h(a),LOG_VGA);break;case 3:this.planar_rotate_reg=a;dbg_log("plane rotate: "+h(a),LOG_VGA);break;case 4:this.plane_read=a;dbg_log("plane read: "+h(a),LOG_VGA);break;case 5:var b=this.planar_mode;this.planar_mode=
a;dbg_log("planar mode: "+h(a),LOG_VGA);(b^a)&96&&this.complete_replot();break;case 6:dbg_log("miscellaneous graphics register: "+h(a),LOG_VGA);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care=a;dbg_log("color don't care: "+h(a),LOG_VGA);break;case 8:this.planar_bitmap=a;dbg_log("planar bitmap: "+h(a),LOG_VGA);break;default:dbg_log("3CF / graphics write "+h(this.graphics_index)+": "+h(a),LOG_VGA)}};
VGAScreen.prototype.port3CF_read=function(){dbg_log("3CF / graphics read "+h(this.graphics_index),LOG_VGA);switch(this.graphics_index){case 0:return this.planar_setreset;case 1:return this.planar_setreset_enable;case 2:return this.color_compare;case 3:return this.planar_rotate_reg;case 4:return this.plane_read;case 5:return this.planar_mode;case 6:return this.miscellaneous_graphics_register;case 7:return this.color_dont_care;case 8:return this.planar_bitmap}return 0};
VGAScreen.prototype.port3D4_write=function(a){dbg_log("3D4 / crtc index: "+a,LOG_VGA);this.index_crtc=a};VGAScreen.prototype.port3D4_read=function(){dbg_log("3D4 read / crtc index: "+this.index_crtc,LOG_VGA);return this.index_crtc};
VGAScreen.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:dbg_log("3D5 / hdisp enable end write: "+h(a),LOG_VGA);this.horizontal_display_enable_end!==a&&(this.horizontal_display_enable_end=a,this.update_vga_size());break;case 2:this.horizontal_blank_start!==a&&(this.horizontal_blank_start=a,this.update_vga_size());break;case 7:dbg_log("3D5 / overflow register write: "+h(a),LOG_VGA);var b=this.vertical_display_enable_end;this.vertical_display_enable_end&=255;this.vertical_display_enable_end=
this.vertical_display_enable_end|a<<3&512|a<<7&256;b!=this.vertical_display_enable_end&&this.update_vga_size();this.line_compare=this.line_compare&767|a<<4&256;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&767|a<<5&256;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 8:dbg_log("3D5 / preset row scan write: "+h(a),LOG_VGA);this.preset_row_scan=a;this.update_layers();break;case 9:dbg_log("3D5 / max scan line write: "+h(a),LOG_VGA);
this.max_scan_line=a;this.line_compare=this.line_compare&511|a<<3&512;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&511|a<<4&512;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 10:dbg_log("3D5 / cursor scanline start write: "+h(a),LOG_VGA);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:dbg_log("3D5 / cursor scanline end write: "+h(a),LOG_VGA);this.cursor_scanline_end=a;this.update_cursor_scanline();break;
case 12:(this.start_address>>8&255)!==a&&(this.start_address=this.start_address&255|a<<8,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());dbg_log("3D5 / start addr hi write: "+h(a)+" -> "+h(this.start_address,4),LOG_VGA);break;case 13:(this.start_address&255)!==a&&(this.start_address=this.start_address&65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());dbg_log("3D5 / start addr lo write: "+h(a)+" -> "+h(this.start_address,4),LOG_VGA);break;case 14:dbg_log("3D5 / cursor address hi write: "+
h(a),LOG_VGA);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:dbg_log("3D5 / cursor address lo write: "+h(a),LOG_VGA);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:dbg_log("3D5 / vdisp enable end write: "+h(a),LOG_VGA);(this.vertical_display_enable_end&255)!==a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:dbg_log("3D5 / offset register write: "+h(a),LOG_VGA);
this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:dbg_log("3D5 / underline location write: "+h(a),LOG_VGA);this.underline_location_register!==a&&(b=this.underline_location_register,this.underline_location_register=a,this.update_vga_size(),(b^a)&64&&this.complete_replot());break;case 21:dbg_log("3D5 / vertical blank start write: "+h(a),LOG_VGA);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&
768|a,this.update_vga_size());break;case 23:dbg_log("3D5 / crtc mode write: "+h(a),LOG_VGA);this.crtc_mode!==a&&(b=this.crtc_mode,this.crtc_mode=a,this.update_vga_size(),(b^a)&67&&this.complete_replot());break;case 24:dbg_log("3D5 / line compare write: "+h(a),LOG_VGA);this.line_compare=this.line_compare&768|a;this.update_layers();break;default:this.index_crtc<this.crtc.length&&(this.crtc[this.index_crtc]=a),dbg_log("3D5 / CRTC write "+h(this.index_crtc)+": "+h(a),LOG_VGA)}};
VGAScreen.prototype.port3D5_read=function(){dbg_log("3D5 read "+h(this.index_crtc),LOG_VGA);switch(this.index_crtc){case 1:return this.horizontal_display_enable_end;case 2:return this.horizontal_blank_start;case 7:return this.vertical_display_enable_end>>7&2|this.vertical_blank_start>>5&8|this.line_compare>>4&16|this.vertical_display_enable_end>>3&64;case 8:return this.preset_row_scan;case 9:return this.max_scan_line;case 10:return this.cursor_scanline_start;case 11:return this.cursor_scanline_end;
case 12:return this.start_address&255;case 13:return this.start_address>>8;case 14:return this.cursor_address>>8;case 15:return this.cursor_address&255;case 18:return this.vertical_display_enable_end&255;case 19:return this.offset_register;case 20:return this.underline_location_register;case 21:return this.vertical_blank_start&255;case 23:return this.crtc_mode;case 24:return this.line_compare&255}return this.index_crtc<this.crtc.length?this.crtc[this.index_crtc]:0};
VGAScreen.prototype.port3DA_read=function(){dbg_log("3DA read - status 1 and clear attr index",LOG_VGA);var a=this.port_3DA_value;this.graphical_mode?(this.port_3DA_value^=1,this.port_3DA_value&=1):(this.port_3DA_value&1&&(this.port_3DA_value^=8),this.port_3DA_value^=1);this.attribute_controller_index=-1;return a};VGAScreen.prototype.port1CE_write=function(a){this.dispi_index=a};
VGAScreen.prototype.port1CF_write=function(a){dbg_log("1CF / dispi write "+h(this.dispi_index)+": "+h(a),LOG_VGA);switch(this.dispi_index){case 1:this.svga_width=a;this.svga_width>MAX_XRES&&(dbg_log("svga_width reduced from "+this.svga_width+" to "+MAX_XRES,LOG_VGA),this.svga_width=MAX_XRES);break;case 2:this.svga_height=a;this.svga_height>MAX_YRES&&(dbg_log("svga_height reduced from "+this.svga_height+" to "+MAX_YRES,LOG_VGA),this.svga_height=MAX_YRES);break;case 3:this.svga_bpp=a;break;case 4:this.svga_enabled=
1===(a&1);this.dispi_enable_value=a;break;case 5:dbg_log("SVGA bank offset: "+h(a<<16),LOG_VGA);this.svga_bank_offset=a<<16;break;case 9:const b=a*this.svga_width;dbg_log("SVGA offset: "+h(b)+" y="+h(a),LOG_VGA);this.svga_offset!==b&&(this.svga_offset=b,this.complete_redraw())}!this.svga_enabled||this.svga_width&&this.svga_height||(dbg_log("SVGA: disabled because of invalid width/height: "+this.svga_width+"x"+this.svga_height,LOG_VGA),this.svga_enabled=!1);dbg_assert(4!==this.svga_bpp,"unimplemented svga bpp: 4");
dbg_assert(4===this.svga_bpp||8===this.svga_bpp||15===this.svga_bpp||16===this.svga_bpp||24===this.svga_bpp||32===this.svga_bpp,"unexpected svga bpp: "+this.svga_bpp);dbg_log("SVGA: enabled="+this.svga_enabled+", "+this.svga_width+"x"+this.svga_height+"x"+this.svga_bpp,LOG_VGA);this.svga_enabled&&4===this.dispi_index&&(this.set_size_graphical(this.svga_width,this.svga_height,this.svga_bpp,this.svga_width,this.svga_height),this.bus.send("screen-set-mode",!0),this.graphical_mode_is_linear=this.graphical_mode=
!0);this.svga_enabled||(this.svga_bank_offset=0);this.update_layers()};VGAScreen.prototype.port1CF_read=function(){dbg_log("1CF / dispi read "+h(this.dispi_index),LOG_VGA);return this.svga_register_read(this.dispi_index)};
VGAScreen.prototype.svga_register_read=function(a){switch(a){case 0:return 45248;case 1:return this.dispi_enable_value&2?MAX_XRES:this.svga_width;case 2:return this.dispi_enable_value&2?MAX_YRES:this.svga_height;case 3:return this.dispi_enable_value&2?MAX_BPP:this.svga_bpp;case 4:return this.dispi_enable_value;case 5:return this.svga_bank_offset>>>16;case 6:return this.screen_width?this.screen_width:1;case 8:return 0;case 10:return this.vga_memory_size/VGA_BANK_SIZE|0}return 255};
VGAScreen.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|15,VGA_PIXEL_BUFFER_SIZE-1),c=this.vga_addr_shift_count(),d=~this.crtc_mode&3,e=this.planar_mode&96,g=this.attribute_mode&64;a<=b;){var f=a>>>c;if(d){var k=a/this.virtual_width|0,m=a-this.virtual_width*k;switch(d){case 1:f=(k&1)<<13;k>>>=1;break;case 2:f=(k&1)<<14;k>>>=1;break;case 3:f=(k&3)<<13,k>>>=2}f|=(k*this.virtual_width+m>>>c)+this.start_address}k=this.plane0[f];m=this.plane1[f];var l=this.plane2[f],
n=this.plane3[f];f=new Uint8Array(8);switch(e){case 0:k<<=0;m<<=1;l<<=2;n<<=3;for(var p=7;0<=p;p--)f[7-p]=k>>p&1|m>>p&2|l>>p&4|n>>p&8;break;case 32:f[0]=k>>6&3|l>>4&12;f[1]=k>>4&3|l>>2&12;f[2]=k>>2&3|l>>0&12;f[3]=k>>0&3|l<<2&12;f[4]=m>>6&3|n>>4&12;f[5]=m>>4&3|n>>2&12;f[6]=m>>2&3|n>>0&12;f[7]=m>>0&3|n<<2&12;break;case 64:case 96:f[0]=k>>4&15,f[1]=k>>0&15,f[2]=m>>4&15,f[3]=m>>0&15,f[4]=l>>4&15,f[5]=l>>0&15,f[6]=n>>4&15,f[7]=n>>0&15}if(g)for(k=p=0;4>p;p++,a++,k+=2)this.pixel_buffer[a]=f[k]<<4|f[k+1];
else for(p=0;8>p;p++,a++)this.pixel_buffer[a]=f[p]}};
VGAScreen.prototype.vga_redraw=function(){var a=this.diff_addr_min,b=Math.min(this.diff_addr_max,VGA_PIXEL_BUFFER_SIZE-1);const c=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.virtual_width*this.virtual_height);var d=255,e=0;this.attribute_mode&128&&(d&=207,e|=this.color_select<<4&48);if(this.attribute_mode&64)for(;a<=b;a++){var g=this.pixel_buffer[a]&d|e;g=this.vga256_palette[g];c[a]=g&65280|g<<16|g>>16|4278190080}else for(d&=63,e|=this.color_select<<4&192;a<=b;a++)g=this.dac_map[this.pixel_buffer[a]&
this.color_plane_enable]&d|e,g=this.vga256_palette[g],c[a]=g&65280|g<<16|g>>16|4278190080};
VGAScreen.prototype.screen_fill_buffer=function(){if(this.graphical_mode){if(0===this.image_data.data.byteLength){var a=new Uint8ClampedArray(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,4*this.virtual_width*this.virtual_height);this.image_data=new ImageData(a,this.virtual_width,this.virtual_height);this.update_layers()}if(this.svga_enabled){a=0;let d=this.svga_height;if(8===this.svga_bpp){const e=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.screen_width*this.screen_height),
g=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[g[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.bus.send("screen-fill-buffer-end",[{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.bus.send("screen-fill-buffer-end",this.layers);this.reset_diffs()}this.update_vertical_retrace()};let PS2_LOG_VERBOSE=!1;
function PS2(a,b){this.cpu=a;this.bus=b;this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ByteQueue(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=
!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ByteQueue(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=
2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1;a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}
PS2.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=
this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};
PS2.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=
a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};
PS2.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};PS2.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(dbg_log("Mouse irq",LOG_PS2),this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};
PS2.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(dbg_log("Keyboard irq",LOG_PS2),this.cpu.device_lower_irq(1),this.cpu.device_raise_irq(1))};PS2.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(dbg_log("adding kbd code: "+h(a),LOG_PS2),this.kbd_buffer.push(a),this.raise_irq())};
PS2.prototype.mouse_send_delta=function(a,b){if(this.have_mouse&&this.use_mouse){var c=this.resolution*this.sample_rate/80;this.mouse_delta_x+=a*c;this.mouse_delta_y+=b*c;this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b)&&(Date.now(),this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))}};PS2.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};
PS2.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);PS2_LOG_VERBOSE&&dbg_log("adding mouse packets: "+[c,a,b],LOG_PS2);this.raise_irq()};
PS2.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};
PS2.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return dbg_log("Port 60 read: Empty",LOG_PS2),this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=this.mouse_buffer.shift(),dbg_log("Port 60 read (mouse): "+h(this.last_port60_byte),LOG_PS2)):(this.cpu.device_lower_irq(1),this.last_port60_byte=this.kbd_buffer.shift(),dbg_log("Port 60 read (kbd) : "+h(this.last_port60_byte),LOG_PS2));(this.kbd_buffer.length||
this.mouse_buffer.length)&&this.raise_irq();return this.last_port60_byte};PS2.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);dbg_log("port 64 read: "+h(a),LOG_PS2);return a};
PS2.prototype.port60_write=function(a){dbg_log("port 60 write: "+h(a),LOG_PS2);if(this.read_command_register)this.command_register=a,this.read_command_register=!1,dbg_log("Keyboard command register = "+h(this.command_register),LOG_PS2);else if(this.read_output_register)this.read_output_register=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(a),this.mouse_irq();else if(this.next_read_sample){this.next_read_sample=!1;this.mouse_buffer.clear();this.mouse_buffer.push(250);this.sample_rate=a;switch(this.mouse_detect_state){case -1:60===
a?(this.mouse_reset_workaround=!0,this.mouse_detect_state=0):(this.mouse_reset_workaround=!1,this.mouse_detect_state=200===a?1:0);break;case 0:200===a&&(this.mouse_detect_state=1);break;case 1:this.mouse_detect_state=100===a?2:200===a?3:0;break;case 2:80===a&&(this.mouse_id=3);this.mouse_detect_state=-1;break;case 3:80===a&&(this.mouse_id=4),this.mouse_detect_state=-1}dbg_log("mouse sample rate: "+h(a)+", mouse id: "+h(this.mouse_id),LOG_PS2);this.sample_rate||(dbg_log("invalid sample rate, reset to 100",
LOG_PS2),this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(250),3<a?(this.resolution=4,dbg_log("invalid resolution, resetting to 4",LOG_PS2)):(this.resolution=1<<a,dbg_log("resolution: "+this.resolution,LOG_PS2)),this.mouse_irq();else if(this.next_read_led)this.next_read_led=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_handle_scan_code_set)this.next_handle_scan_code_set=!1,this.kbd_buffer.push(250),
this.kbd_irq(),a||this.kbd_buffer.push(2);else if(this.next_read_rate)this.next_read_rate=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_is_mouse_command){if(this.next_is_mouse_command=!1,dbg_log("Port 60 data register write: "+h(a),LOG_PS2),this.have_mouse){this.kbd_buffer.clear();this.mouse_buffer.clear();this.mouse_buffer.push(250);switch(a){case 230:dbg_log("Scaling 1:1",LOG_PS2);this.scaling2=!1;break;case 231:dbg_log("Scaling 2:1",LOG_PS2);this.scaling2=!0;break;case 232:this.next_read_resolution=
!0;break;case 233:this.send_mouse_packet(0,0);break;case 235:dbg_log("unimplemented request single packet",LOG_PS2);this.send_mouse_packet(0,0);break;case 242:dbg_log("required id: "+h(this.mouse_id),LOG_PS2);this.mouse_buffer.push(this.mouse_id);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;this.raise_irq();break;case 243:this.next_read_sample=!0;break;case 244:this.use_mouse=this.enable_mouse_stream=!0;this.bus.send("mouse-enable",!0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=
0;break;case 245:this.enable_mouse_stream=!1;break;case 246:this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;break;case 255:dbg_log("Mouse reset",LOG_PS2);this.mouse_buffer.push(170);this.mouse_buffer.push(0);this.use_mouse=!0;this.bus.send("mouse-enable",!0);this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;this.mouse_reset_workaround||(this.mouse_id=0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;default:dbg_log("Unimplemented mouse command: "+
h(a),LOG_PS2)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=a;else{dbg_log("Port 60 data register write: "+h(a),LOG_PS2);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(83);break;case 243:this.next_read_rate=!0;break;case 244:dbg_log("kbd enable scanning",
LOG_PS2);this.enable_keyboard_stream=!0;break;case 245:dbg_log("kbd disable scanning",LOG_PS2);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:dbg_log("Unimplemented keyboard command: "+h(a),LOG_PS2)}this.kbd_irq()}};
PS2.prototype.port64_write=function(a){dbg_log("port 64 write: "+h(a),LOG_PS2);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:dbg_log("Disable second port",LOG_PS2);this.command_register|=32;break;case 168:dbg_log("Enable second port",
LOG_PS2);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:dbg_log("Disable Keyboard",LOG_PS2);this.command_register|=16;break;case 174:dbg_log("Enable Keyboard",LOG_PS2);this.command_register&=-17;
break;case 254:dbg_log("CPU reboot via PS2");this.cpu.reboot_internal();break;default:dbg_log("port 64: Unimplemented command byte: "+h(a),LOG_PS2)}};var PIC_LOG_VERBOSE=!1;
function PIC(a,b){this.irq_value=this.irr=this.isr=this.irq_map=this.irq_mask=0;this.requested_irq=-1;this.master=b;this.is_master=void 0===this.master;this.slave=void 0;this.name=this.is_master?"master":"slave ";this.expect_icw4=!1;this.read_isr=this.state=0;this.auto_eoi=1;this.elcr=this.special_mask_mode=0;this.cpu=a;this.is_master?(this.slave=new PIC(this.cpu,this),this.check_irqs=function(){if(0<=this.requested_irq)PIC_LOG_VERBOSE&&dbg_log("master> Already requested irq: "+this.requested_irq,
LOG_PIC),this.cpu.handle_irqs();else{var c=this.irr&this.irq_mask;if(c){c&=-c;var d=this.special_mask_mode?this.irq_mask:-1;this.isr&&(this.isr&-this.isr&d)<=c?dbg_log("master> higher prio: isr="+h(this.isr,2)+" mask="+h(this.irq_mask&255,2)+" irq="+h(c,2),LOG_PIC):(dbg_assert(0!==c),d=v86util.int_log2_byte(c),dbg_assert(c===1<<d),PIC_LOG_VERBOSE&&dbg_log("master> request irq "+d,LOG_PIC),this.requested_irq=d,this.cpu.handle_irqs())}else PIC_LOG_VERBOSE&&dbg_log("master> no unmasked irrs. irr="+h(this.irr,
2)+" mask="+h(this.irq_mask&255,2)+" isr="+h(this.isr,2),LOG_PIC)}},this.acknowledge_irq=function(){if(-1!==this.requested_irq)if(0===this.irr)PIC_LOG_VERBOSE&&dbg_log("master> spurious requested="+this.requested_irq,LOG_PIC),this.requested_irq=-1;else{dbg_assert(this.irr);dbg_assert(0<=this.requested_irq);var c=1<<this.requested_irq;0===(this.elcr&c)&&(this.irr&=~c);this.auto_eoi||(this.isr|=c);PIC_LOG_VERBOSE&&dbg_log("master> acknowledge "+this.requested_irq,LOG_PIC);2===this.requested_irq?this.slave.acknowledge_irq():
this.cpu.pic_call_irq(this.irq_map|this.requested_irq);this.requested_irq=-1;this.check_irqs()}}):(this.check_irqs=function(){if(0<=this.requested_irq)PIC_LOG_VERBOSE&&dbg_log("slave > Already requested irq: "+this.requested_irq,LOG_PIC),this.cpu.handle_irqs();else{var c=this.irr&this.irq_mask;if(c){c&=-c;var d=this.special_mask_mode?this.irq_mask:-1;this.isr&&(this.isr&-this.isr&d)<=c?PIC_LOG_VERBOSE&&dbg_log("slave > higher prio: isr="+h(this.isr,2)+" irq="+h(c,2),LOG_PIC):(dbg_assert(0!==c),d=
v86util.int_log2_byte(c),dbg_assert(c===1<<d),PIC_LOG_VERBOSE&&dbg_log("slave > request irq "+d,LOG_PIC),this.requested_irq=d,this.master.set_irq(2))}else PIC_LOG_VERBOSE&&dbg_log("slave > no unmasked irrs. irr="+h(this.irr,2)+" mask="+h(this.irq_mask&255,2)+" isr="+h(this.isr,2),LOG_PIC)}},this.acknowledge_irq=function(){if(-1!==this.requested_irq)if(0===this.irr)PIC_LOG_VERBOSE&&dbg_log("slave > spurious requested="+this.requested_irq,LOG_PIC),this.requested_irq=-1,this.master.irq_value&=-5,this.cpu.pic_call_irq(this.irq_map|
7);else{dbg_assert(this.irr);dbg_assert(0<=this.requested_irq);var c=1<<this.requested_irq;0===(this.elcr&c)&&(this.irr&=~c);this.auto_eoi||(this.isr|=c);this.master.irq_value&=-5;PIC_LOG_VERBOSE&&dbg_log("slave > acknowledge "+this.requested_irq,LOG_PIC);this.cpu.pic_call_irq(this.irq_map|this.requested_irq);this.requested_irq=-1;this.check_irqs()}});this.dump=function(){dbg_log("mask: "+h(this.irq_mask&255),LOG_PIC);dbg_log("base: "+h(this.irq_map),LOG_PIC);dbg_log("requested: "+h(this.irr),LOG_PIC);
dbg_log("serviced: "+h(this.isr),LOG_PIC);this.is_master&&this.slave.dump()};this.is_master?(a=32,b=1232):(a=160,b=1233);this.cpu.io.register_write(a,this,this.port20_write);this.cpu.io.register_read(a,this,this.port20_read);this.cpu.io.register_write(a|1,this,this.port21_write);this.cpu.io.register_read(a|1,this,this.port21_read);this.cpu.io.register_write(b,this,this.port4D0_write);this.cpu.io.register_read(b,this,this.port4D0_read);this.is_master?(this.set_irq=function(c){dbg_assert(0<=c&&16>c);
if(8<=c)this.slave.set_irq(c-8);else{var d=1<<c;0===(this.irq_value&d)?(PIC_LOG_VERBOSE&&dbg_log("master> set irq "+c,LOG_PIC),this.irr|=d,this.irq_value|=d,this.check_irqs()):PIC_LOG_VERBOSE&&dbg_log("master> set irq "+c+": already set!",LOG_PIC)}},this.clear_irq=function(c){dbg_assert(0<=c&&16>c);PIC_LOG_VERBOSE&&dbg_log("master> clear irq "+c,LOG_PIC);8<=c?this.slave.clear_irq(c-8):(c=1<<c,this.irq_value&c&&(this.irq_value&=~c,this.irr&=~c,this.check_irqs()))}):(this.set_irq=function(c){dbg_assert(0<=
c&&8>c);var d=1<<c;0===(this.irq_value&d)?(PIC_LOG_VERBOSE&&dbg_log("slave > set irq "+c,LOG_PIC),this.irr|=d,this.irq_value|=d,this.check_irqs()):PIC_LOG_VERBOSE&&dbg_log("slave > set irq "+c+": already set!",LOG_PIC)},this.clear_irq=function(c){dbg_assert(0<=c&&8>c);PIC_LOG_VERBOSE&&dbg_log("slave > clear irq "+c,LOG_PIC);c=1<<c;this.irq_value&c&&(this.irq_value&=~c,this.irr&=~c,this.check_irqs())});this.get_isr=function(){return this.isr}}
PIC.prototype.get_state=function(){var a=[];a[0]=this.irq_mask;a[1]=this.irq_map;a[2]=this.isr;a[3]=this.irr;a[4]=this.is_master;a[5]=this.slave;a[6]=this.expect_icw4;a[7]=this.state;a[8]=this.read_isr;a[9]=this.auto_eoi;a[10]=this.elcr;return a};PIC.prototype.set_state=function(a){this.irq_mask=a[0];this.irq_map=a[1];this.isr=a[2];this.irr=a[3];this.is_master=a[4];this.slave&&this.slave.set_state(a[5]);this.expect_icw4=a[6];this.state=a[7];this.read_isr=a[8];this.auto_eoi=a[9];this.elcr=a[10]};
PIC.prototype.port20_write=function(a){if(a&16)dbg_log("icw1 = "+h(a),LOG_PIC),this.irq_value=this.irq_mask=this.irr=this.isr=0,this.auto_eoi=1,this.requested_irq=-1,this.expect_icw4=a&1,this.state=1;else if(a&8)dbg_log("ocw3: "+h(a),LOG_PIC),a&2&&(this.read_isr=a&1),a&4&&dbg_assert(!1,"unimplemented: polling",LOG_PIC),a&64&&(this.special_mask_mode=32===(a&32),dbg_log("special mask mode: "+this.special_mask_mode,LOG_PIC));else{dbg_log("eoi: "+h(a)+" ("+this.name+")",LOG_PIC);var b=a>>5;1===b?(this.isr&=
this.isr-1,dbg_log("new isr: "+h(this.isr,2),LOG_PIC)):3===b?this.isr&=~(1<<(a&7)):192===(a&200)?dbg_log("lowest priority: "+h(a&7),LOG_PIC):(dbg_log("Unknown eoi: "+h(a),LOG_PIC),dbg_assert(!1),this.isr&=this.isr-1);this.check_irqs()}};PIC.prototype.port20_read=function(){if(this.read_isr)return dbg_log("read port 20h (isr): "+h(this.isr),LOG_PIC),this.isr;dbg_log("read port 20h (irr): "+h(this.irr),LOG_PIC);return this.irr};
PIC.prototype.port21_write=function(a){0===this.state?this.expect_icw4?(this.expect_icw4=!1,this.auto_eoi=a&2,dbg_log("icw4: "+h(a)+" autoeoi="+this.auto_eoi,LOG_PIC),0===(a&1)&&dbg_assert(!1,"unimplemented: not 8086 mode",LOG_PIC)):(this.irq_mask=~a,PIC_LOG_VERBOSE&&dbg_log("interrupt mask: "+(this.irq_mask&255).toString(2)+" ("+this.name+")",LOG_PIC),this.check_irqs()):1===this.state?(this.irq_map=a,dbg_log("interrupts are mapped to "+h(this.irq_map)+" ("+this.name+")",LOG_PIC),this.state++):2===
this.state&&(this.state=0,dbg_log("icw3: "+h(a),LOG_PIC))};PIC.prototype.port21_read=function(){dbg_log("21h read "+h(~this.irq_mask&255),LOG_PIC);return~this.irq_mask&255};PIC.prototype.port4D0_read=function(){dbg_log("elcr read: "+h(this.elcr,2),LOG_PIC);return this.elcr};PIC.prototype.port4D0_write=function(a){dbg_log("elcr write: "+h(a,2),LOG_PIC);this.elcr=a};var CMOS_RTC_SECONDS=0,CMOS_RTC_SECONDS_ALARM=1,CMOS_RTC_MINUTES=2,CMOS_RTC_MINUTES_ALARM=3,CMOS_RTC_HOURS=4,CMOS_RTC_HOURS_ALARM=5,CMOS_RTC_DAY_WEEK=6,CMOS_RTC_DAY_MONTH=7,CMOS_RTC_MONTH=8,CMOS_RTC_YEAR=9,CMOS_STATUS_A=10,CMOS_STATUS_B=11,CMOS_STATUS_C=12,CMOS_STATUS_D=13,CMOS_RESET_CODE=15,CMOS_FLOPPY_DRIVE_TYPE=16,CMOS_DISK_DATA=18,CMOS_EQUIPMENT_INFO=20,CMOS_MEM_BASE_LOW=21,CMOS_MEM_BASE_HIGH=22,CMOS_MEM_OLD_EXT_LOW=23,CMOS_MEM_OLD_EXT_HIGH=24,CMOS_DISK_DRIVE1_TYPE=25,CMOS_DISK_DRIVE2_TYPE=26,
CMOS_DISK_DRIVE1_CYL=27,CMOS_DISK_DRIVE2_CYL=36,CMOS_MEM_EXTMEM_LOW=48,CMOS_MEM_EXTMEM_HIGH=49,CMOS_CENTURY=50,CMOS_MEM_EXTMEM2_LOW=52,CMOS_MEM_EXTMEM2_HIGH=53,CMOS_BIOS_BOOTFLAG1=56,CMOS_BIOS_DISKTRANSFLAG=57,CMOS_BIOS_BOOTFLAG2=61,CMOS_MEM_HIGHMEM_LOW=91,CMOS_MEM_HIGHMEM_MID=92,CMOS_MEM_HIGHMEM_HIGH=93,CMOS_BIOS_SMP_COUNT=95;
function RTC(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=2;this.nmi_disabled=this.cmos_c=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}
RTC.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;return a};
RTC.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11]};
RTC.prototype.timer=function(a,b){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a&&(this.cpu.device_raise_irq(8),this.cmos_c|=160,this.next_interrupt_alarm=0);b=100;this.periodic_interrupt&&this.next_interrupt&&(b=Math.min(b,
Math.max(0,this.next_interrupt-a)));this.next_interrupt_alarm&&(b=Math.min(b,Math.max(0,this.next_interrupt_alarm-a)));return b};RTC.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};RTC.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;dbg_assert(256>a);dbg_assert(10>b);dbg_assert(10>c);return b+10*c};RTC.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};RTC.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};
RTC.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case CMOS_RTC_SECONDS:return this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case CMOS_RTC_MINUTES:return this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case CMOS_RTC_HOURS:return this.encode_time((new Date(this.rtc_time)).getUTCHours());case CMOS_RTC_DAY_MONTH:return this.encode_time((new Date(this.rtc_time)).getUTCDate());case CMOS_RTC_MONTH:return this.encode_time((new Date(this.rtc_time)).getUTCMonth()+
1);case CMOS_RTC_YEAR:return this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case CMOS_STATUS_A:return 999<=v86.microtick()%1E3?this.cmos_a|128:this.cmos_a;case CMOS_STATUS_B:return this.cmos_b;case CMOS_STATUS_C:return this.cpu.device_lower_irq(8),dbg_log("cmos reg C read",LOG_RTC),a=this.cmos_c,this.cmos_c&=-241,a;case CMOS_STATUS_D:return 0;case CMOS_CENTURY:return this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return dbg_log("cmos read from index "+
h(a),LOG_RTC),this.cmos_data[this.cmos_index]}};
RTC.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);dbg_log("Periodic interrupt, a="+h(this.cmos_a,2)+" t="+this.periodic_interrupt_time,LOG_RTC);break;case 11:this.cmos_b=a;this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[CMOS_RTC_SECONDS_ALARM]),c=this.decode_time(this.cmos_data[CMOS_RTC_MINUTES_ALARM]),d=this.decode_time(this.cmos_data[CMOS_RTC_HOURS_ALARM]),
e=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b));dbg_log("RTC alarm scheduled for "+e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),LOG_RTC);this.next_interrupt_alarm=+e}this.cmos_b&16&&dbg_log("Unimplemented: updated interrupt",LOG_RTC);dbg_log("cmos b="+h(this.cmos_b,2),LOG_RTC);break;case CMOS_RTC_SECONDS_ALARM:case CMOS_RTC_MINUTES_ALARM:case CMOS_RTC_HOURS_ALARM:this.cmos_write(this.cmos_index,a);break;default:dbg_log("cmos write index "+h(this.cmos_index)+": "+
h(a),LOG_RTC)}this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};RTC.prototype.cmos_read=function(a){dbg_assert(128>a);return this.cmos_data[a]};RTC.prototype.cmos_write=function(a,b){dbg_log("cmos "+h(a)+" <- "+h(b),LOG_RTC);dbg_assert(128>a);this.cmos_data[a]=b};var DLAB=128,UART_IER_MSI=8,UART_IER_THRI=2,UART_IER_RDI=1,UART_IIR_MSI=0,UART_IIR_NO_INT=1,UART_IIR_THRI=2,UART_IIR_RDI=4,UART_IIR_RLSI=6,UART_IIR_CTI=12,UART_LSR_DATA_READY=1,UART_LSR_TX_EMPTY=32,UART_LSR_TRANSMITTER_EMPTY=64;
function UART(a,b,c){this.bus=c;this.cpu=a;this.ints=1<<UART_IIR_THRI;this.line_control=this.baud_rate=0;this.lsr=UART_LSR_TRANSMITTER_EMPTY|UART_LSR_TX_EMPTY;this.ier=this.fifo_control=0;this.iir=UART_IIR_NO_INT;this.irq=this.scratch_register=this.modem_status=this.modem_control=0;this.input=new ByteQueue(4096);this.current_line=[];switch(b){case 1016:this.com=0;this.irq=4;break;case 760:this.com=1;this.irq=3;break;case 1E3:this.com=2;this.irq=4;break;case 744:this.irq=this.com=3;break;default:dbg_log("Invalid serial port: "+
h(b),LOG_SERIAL),this.com=0,this.irq=4}this.bus.register("serial"+this.com+"-input",function(d){this.data_received(d)},this);a=a.io;a.register_write(b,this,function(d){this.write_data(d)},function(d){this.write_data(d&255);this.write_data(d>>8)});a.register_write(b|1,this,function(d){this.line_control&DLAB?(this.baud_rate=this.baud_rate&255|d<<8,dbg_log("baud rate: "+h(this.baud_rate),LOG_SERIAL)):(0===(this.ier&UART_IIR_THRI)&&d&UART_IIR_THRI&&this.ThrowInterrupt(UART_IIR_THRI),this.ier=d&15,dbg_log("interrupt enable: "+
h(d),LOG_SERIAL),this.CheckInterrupt())});a.register_read(b,this,function(){if(this.line_control&DLAB)return this.baud_rate&255;var d=this.input.shift();-1===d?dbg_log("Read input empty",LOG_SERIAL):dbg_log("Read input: "+h(d),LOG_SERIAL);0===this.input.length&&(this.lsr&=~UART_LSR_DATA_READY,this.ClearInterrupt(UART_IIR_CTI),this.ClearInterrupt(UART_IIR_RDI));return d});a.register_read(b|1,this,function(){return this.line_control&DLAB?this.baud_rate>>8:this.ier&15});a.register_read(b|2,this,function(){var d=
this.iir&15;dbg_log("read interrupt identification: "+h(this.iir),LOG_SERIAL);this.iir==UART_IIR_THRI&&this.ClearInterrupt(UART_IIR_THRI);this.fifo_control&1&&(d|=192);return d});a.register_write(b|2,this,function(d){dbg_log("fifo control: "+h(d),LOG_SERIAL);this.fifo_control=d});a.register_read(b|3,this,function(){dbg_log("read line control: "+h(this.line_control),LOG_SERIAL);return this.line_control});a.register_write(b|3,this,function(d){dbg_log("line control: "+h(d),LOG_SERIAL);this.line_control=
d});a.register_read(b|4,this,function(){return this.modem_control});a.register_write(b|4,this,function(d){dbg_log("modem control: "+h(d),LOG_SERIAL);this.modem_control=d});a.register_read(b|5,this,function(){dbg_log("read line status: "+h(this.lsr),LOG_SERIAL);return this.lsr});a.register_write(b|5,this,function(d){dbg_log("Factory test write",LOG_SERIAL)});a.register_read(b|6,this,function(){dbg_log("read modem status: "+h(this.modem_status),LOG_SERIAL);return this.modem_status});a.register_write(b|
6,this,function(d){dbg_log("Unkown register write (base+6)",LOG_SERIAL)});a.register_read(b|7,this,function(){return this.scratch_register});a.register_write(b|7,this,function(d){this.scratch_register=d})}UART.prototype.get_state=function(){var a=[];a[0]=this.ints;a[1]=this.baud_rate;a[2]=this.line_control;a[3]=this.lsr;a[4]=this.fifo_control;a[5]=this.ier;a[6]=this.iir;a[7]=this.modem_control;a[8]=this.modem_status;a[9]=this.scratch_register;a[10]=this.irq;return a};
UART.prototype.set_state=function(a){this.ints=a[0];this.baud_rate=a[1];this.line_control=a[2];this.lsr=a[3];this.fifo_control=a[4];this.ier=a[5];this.iir=a[6];this.modem_control=a[7];this.modem_status=a[8];this.scratch_register=a[9];this.irq=a[10]};
UART.prototype.CheckInterrupt=function(){this.ints&1<<UART_IIR_CTI&&this.ier&UART_IER_RDI?(this.iir=UART_IIR_CTI,this.cpu.device_raise_irq(this.irq)):this.ints&1<<UART_IIR_RDI&&this.ier&UART_IER_RDI?(this.iir=UART_IIR_RDI,this.cpu.device_raise_irq(this.irq)):this.ints&1<<UART_IIR_THRI&&this.ier&UART_IER_THRI?(this.iir=UART_IIR_THRI,this.cpu.device_raise_irq(this.irq)):this.ints&1<<UART_IIR_MSI&&this.ier&UART_IER_MSI?(this.iir=UART_IIR_MSI,this.cpu.device_raise_irq(this.irq)):(this.iir=UART_IIR_NO_INT,
this.cpu.device_lower_irq(this.irq))};UART.prototype.ThrowInterrupt=function(a){this.ints|=1<<a;this.CheckInterrupt()};UART.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};UART.prototype.data_received=function(a){dbg_log("input: "+h(a),LOG_SERIAL);this.input.push(a);this.lsr|=UART_LSR_DATA_READY;this.fifo_control&1?this.ThrowInterrupt(UART_IIR_CTI):this.ThrowInterrupt(UART_IIR_RDI)};
UART.prototype.write_data=function(a){if(this.line_control&DLAB)this.baud_rate=this.baud_rate&-256|a;else if(dbg_log("data: "+h(a),LOG_SERIAL),this.ThrowInterrupt(UART_IIR_THRI),255!==a){var b=String.fromCharCode(a);this.bus.send("serial"+this.com+"-output-char",b);this.current_line.push(a);"\n"===b&&(a=String.fromCharCode.apply("",this.current_line).trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g,""),dbg_log("SERIAL: "+a),this.bus.send("serial"+this.com+"-output-line",String.fromCharCode.apply("",
this.current_line)),this.current_line=[])}};var HPET_ADDR=4275044352,HPET_PERIOD=1E8,HPET_FREQ_MS=1E12/HPET_PERIOD,HPET_SUPPORT_64=0,HPET_COUNTER_CONFIG=16|HPET_SUPPORT_64<<5,HPET_COUNTER_CONFIG_MASK=32816,HPET_NUM_COUNTERS=4;
function HPET(a){function b(){return e?(Date.now()-g)*HPET_FREQ_MS+f|0:f}function c(){return HPET_SUPPORT_64?e?(Date.now()-g)*(HPET_FREQ_MS/4294967296)+k|0:k:0}var d=this,e=!1,g=Date.now(),f=0,k=0,m=!1,l=0,n=new Int32Array(HPET_NUM_COUNTERS<<1),p=new Int32Array(HPET_NUM_COUNTERS<<1),t=new Int32Array(HPET_NUM_COUNTERS<<1),r=0;this.legacy_mode=!1;this.timer=function(q){if(!e)return 100;q=b()>>>0;for(var v,u,x=0;x<HPET_NUM_COUNTERS;x++)if(v=n[x<<1],u=p[x<<1]>>>0,r<=q?u>r&&u<=q:u>r||u<=q)u=v&4,v&2?(u=
u&&!(l&1<<x),l|=1<<x):l&=~(1<<x),v&8&&(p[x<<1]+=t[x<<1]),u&&a.device_raise_irq(0);r=q;return 100};a.io.mmap_register(HPET_ADDR,16384,function(q){dbg_log("Read "+h(q,4)+" (ctr="+h(b()>>>0)+")",LOG_HPET);switch(q){case 0:return HPET_NUM_COUNTERS-1<<8|98305|HPET_SUPPORT_64<<13;case 4:return HPET_PERIOD;case 16:return d.legacy_mode<<1|e;case 240:return b();case 244:return c()}var v=q>>2&7,u=q-256>>5;if(256>q||u>=HPET_NUM_COUNTERS||5<v)return dbg_log("Read reserved address: "+h(q),LOG_HPET),0;dbg_log("Read counter: addr="+
h(q)+" counter="+h(u,2)+" reg="+h(v),LOG_HPET);switch(v){case 0:return n[u<<1]&~HPET_COUNTER_CONFIG_MASK|HPET_COUNTER_CONFIG;case 1:return n[u<<1|1];case 2:return p[u<<1];case 3:return p[u<<1|1];case 4:case 5:return 0}},function(q,v){dbg_log("Write "+h(q,4)+": "+h(v,2),LOG_HPET);switch(q){case 16:dbg_log("conf: enabled="+(v&1)+" legacy="+(v>>1&1),LOG_HPET);(e^v)&1&&(v&1?g=Date.now():(f=b(),k=c()));e=1===(v&1);d.legacy_mode=2===(v&2);return;case 32:l&=~v;return;case 240:f=v;return;case 244:k=v;return}var u=
q>>2&7,x=q-256>>5;if(256>q||x>=HPET_NUM_COUNTERS||2<u)dbg_log("Write reserved address: "+h(q)+" data="+h(v),LOG_HPET);else switch(dbg_log("Write counter: addr="+h(q)+" counter="+h(x,2)+" reg="+h(u)+" data="+h(v,2),LOG_HPET),u){case 0:n[x<<1]=v;break;case 2:m?(t[x<<1]=v,m=!1,dbg_log("Accumulator acc="+h(v>>>0,8)+" ctr="+h(x,2),LOG_HPET)):(p[x<<1]=v,n[x<<1]&64&&(m=!0,n[x<<1]&=-65));break;case 3:p[x<<1|1]=v}})};var PMTIMER_FREQ_SECONDS=3579545;
function ACPI(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],pci_bars:[],name:"acpi"});this.timer_imprecision_offset=this.timer_last_value=0;this.status=1;this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(v86.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){dbg_log("ACPI pm1_status read",
LOG_ACPI);return this.pm1_status});b.register_write(45056,this,void 0,function(c){dbg_log("ACPI pm1_status write: "+h(c,4),LOG_ACPI);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){dbg_log("ACPI pm1_enable read",LOG_ACPI);return this.pm1_enable});b.register_write(45058,this,void 0,function(c){dbg_log("ACPI pm1_enable write: "+h(c),LOG_ACPI);this.pm1_enable=c});b.register_read(45060,this,void 0,function(){dbg_log("ACPI status read",LOG_ACPI);return this.status});b.register_write(45060,
this,void 0,function(c){dbg_log("ACPI status write: "+h(c),LOG_ACPI);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(v86.microtick())&16777215});b.register_read(45024,this,function(){dbg_log("Read gpe#0",LOG_ACPI);return this.gpe[0]});b.register_read(45025,this,function(){dbg_log("Read gpe#1",LOG_ACPI);return this.gpe[1]});b.register_read(45026,this,function(){dbg_log("Read gpe#2",LOG_ACPI);return this.gpe[2]});b.register_read(45027,this,function(){dbg_log("Read gpe#3",
LOG_ACPI);return this.gpe[3]});b.register_write(45024,this,function(c){dbg_log("Write gpe#0: "+h(c),LOG_ACPI);this.gpe[0]=c});b.register_write(45025,this,function(c){dbg_log("Write gpe#1: "+h(c),LOG_ACPI);this.gpe[1]=c});b.register_write(45026,this,function(c){dbg_log("Write gpe#2: "+h(c),LOG_ACPI);this.gpe[2]=c});b.register_write(45027,this,function(c){dbg_log("Write gpe#3: "+h(c),LOG_ACPI);this.gpe[3]=c})}
ACPI.prototype.timer=function(a){a=this.get_timer(a);var b=0!==((a^this.last_timer)&8388608);this.pm1_enable&1&&b?(dbg_log("ACPI raise irq",LOG_ACPI),this.pm1_status|=1,this.cpu.device_raise_irq(9)):this.cpu.device_lower_irq(9);this.last_timer=a;return 100};
ACPI.prototype.get_timer=function(a){a=Math.round(PMTIMER_FREQ_SECONDS/1E3*a);a===this.timer_last_value?this.timer_imprecision_offset<PMTIMER_FREQ_SECONDS/1E3&&this.timer_imprecision_offset++:(dbg_assert(a>this.timer_last_value),this.timer_last_value+this.timer_imprecision_offset<=a?(this.timer_imprecision_offset=0,this.timer_last_value=a):dbg_log("Warning: Overshot pmtimer, waiting; current="+a+" last="+this.timer_last_value+" offset="+this.timer_imprecision_offset,LOG_ACPI));return this.timer_last_value+
this.timer_imprecision_offset};ACPI.prototype.get_state=function(){var a=[];a[0]=this.status;a[1]=this.pm1_status;a[2]=this.pm1_enable;a[3]=this.gpe;return a};ACPI.prototype.set_state=function(a){this.status=a[0];this.pm1_status=a[1];this.pm1_enable=a[2];this.gpe=a[3]};var APIC_LOG_VERBOSE=!1,APIC_ADDRESS=4276092928,APIC_TIMER_MODE_MASK=393216,APIC_TIMER_MODE_ONE_SHOT=0,APIC_TIMER_MODE_PERIODIC=131072,APIC_TIMER_MODE_TSC=262144,DELIVERY_MODES="Fixed (0);Lowest Prio (1);SMI (2);Reserved (3);NMI (4);INIT (5);Reserved (6);ExtINT (7)".split(";"),DESTINATION_MODES=["physical","logical"];
function APIC(a){this.cpu=a;this.timer_divider=this.apic_id=0;this.timer_divider_shift=1;this.timer_current_count=this.timer_initial_count=0;this.next_tick=v86.microtick();this.lvt_error=this.lvt_int1=this.lvt_int0=this.lvt_perf_counter=this.lvt_timer=IOAPIC_CONFIG_MASKED;this.icr1=this.icr0=this.tpr=0;this.irr=new Int32Array(8);this.isr=new Int32Array(8);this.tmr=new Int32Array(8);this.spurious_vector=254;this.destination_format=-1;this.read_error=this.error=this.local_destination=0;a.io.mmap_register(APIC_ADDRESS,
1048576,b=>{dbg_log("Unsupported read8 from apic: "+h(b>>>0),LOG_APIC);var c=b&3;return this.read32(b&-4)>>8*c&255},(b,c)=>{dbg_log("Unsupported write8 from apic: "+h(b)+" <- "+h(c),LOG_APIC);dbg_trace();dbg_assert(!1)},b=>this.read32(b),(b,c)=>this.write32(b,c))}
APIC.prototype.read32=function(a){a=a-APIC_ADDRESS|0;switch(a){case 32:return dbg_log("APIC read id",LOG_APIC),this.apic_id;case 48:return dbg_log("APIC read version",LOG_APIC),327700;case 128:return APIC_LOG_VERBOSE&&dbg_log("APIC read tpr",LOG_APIC),this.tpr;case 208:return dbg_log("Read local destination",LOG_APIC),this.local_destination;case 224:return dbg_log("Read destination format",LOG_APIC),this.destination_format;case 240:return this.spurious_vector;case 256:case 272:case 288:case 304:case 320:case 336:case 352:case 368:return a=
a-256>>4,dbg_log("Read isr "+a+": "+h(this.isr[a]>>>0,8),LOG_APIC),this.isr[a];case 384:case 400:case 416:case 432:case 448:case 464:case 480:case 496:return a=a-384>>4,dbg_log("Read tmr "+a+": "+h(this.tmr[a]>>>0,8),LOG_APIC),this.tmr[a];case 512:case 528:case 544:case 560:case 576:case 592:case 608:case 624:return a=a-512>>4,dbg_log("Read irr "+a+": "+h(this.irr[a]>>>0,8),LOG_APIC),this.irr[a];case 640:return dbg_log("Read error: "+h(this.read_error>>>0,8),LOG_APIC),this.read_error;case 768:return APIC_LOG_VERBOSE&&
dbg_log("APIC read icr0",LOG_APIC),this.icr0;case 784:return dbg_log("APIC read icr1",LOG_APIC),this.icr1;case 800:return dbg_log("read timer lvt",LOG_APIC),this.lvt_timer;case 832:return dbg_log("read lvt perf counter",LOG_APIC),this.lvt_perf_counter;case 848:return dbg_log("read lvt int0",LOG_APIC),this.lvt_int0;case 864:return dbg_log("read lvt int1",LOG_APIC),this.lvt_int1;case 880:return dbg_log("read lvt error",LOG_APIC),this.lvt_error;case 992:return dbg_log("read timer divider",LOG_APIC),
this.timer_divider;case 896:return dbg_log("read timer initial count",LOG_APIC),this.timer_initial_count;case 912:return dbg_log("read timer current count: "+h(this.timer_current_count>>>0,8),LOG_APIC),this.timer_current_count;default:return dbg_log("APIC read "+h(a),LOG_APIC),dbg_assert(!1),0}};
APIC.prototype.write32=function(a,b){a=a-APIC_ADDRESS|0;switch(a){case 48:dbg_log("APIC write version: "+h(b>>>0,8)+", ignored",LOG_APIC);break;case 128:APIC_LOG_VERBOSE&&dbg_log("Set tpr: "+h(b&255,2),LOG_APIC);this.tpr=b&255;this.check_vector();break;case 176:a=this.highest_isr();-1!==a?(APIC_LOG_VERBOSE&&dbg_log("eoi: "+h(b>>>0,8)+" for vector "+h(a),LOG_APIC),this.register_clear_bit(this.isr,a),this.register_get_bit(this.tmr,a)&&this.cpu.devices.ioapic.remote_eoi(a),this.check_vector()):dbg_log("Bad eoi: No isr set",
LOG_APIC);break;case 208:dbg_log("Set local destination: "+h(b>>>0,8),LOG_APIC);this.local_destination=b&4278190080;break;case 224:dbg_log("Set destination format: "+h(b>>>0,8),LOG_APIC);this.destination_format=b|16777215;break;case 240:dbg_log("Set spurious vector: "+h(b>>>0,8),LOG_APIC);this.spurious_vector=b;break;case 640:dbg_log("Write error: "+h(b>>>0,8),LOG_APIC);this.read_error=this.error;this.error=0;break;case 768:a=b&255;var c=b>>8&7,d=b>>11&1,e=b>>15&1,g=b>>18&3,f=this.icr1>>>24;dbg_log("APIC write icr0: "+
h(b,8)+" vector="+h(a,2)+" destination_mode="+DESTINATION_MODES[d]+" delivery_mode="+DELIVERY_MODES[c]+" destination_shorthand="+["no","self","all with self","all without self"][g],LOG_APIC);this.icr0=b&-4097;0===g?this.route(a,c,e,f,d):1===g?this.deliver(a,IOAPIC_DELIVERY_FIXED,e):2===g?this.deliver(a,c,e):3!==g&&dbg_assert(!1);break;case 784:dbg_log("APIC write icr1: "+h(b>>>0,8),LOG_APIC);this.icr1=b;break;case 800:dbg_log("timer lvt: "+h(b>>>0,8),LOG_APIC);this.lvt_timer=b;break;case 832:dbg_log("lvt perf counter: "+
h(b>>>0,8),LOG_APIC);this.lvt_perf_counter=b;break;case 848:dbg_log("lvt int0: "+h(b>>>0,8),LOG_APIC);this.lvt_int0=b;break;case 864:dbg_log("lvt int1: "+h(b>>>0,8),LOG_APIC);this.lvt_int1=b;break;case 880:dbg_log("lvt error: "+h(b>>>0,8),LOG_APIC);this.lvt_error=b;break;case 992:dbg_log("timer divider: "+h(b>>>0,8),LOG_APIC);this.timer_divider=b;b=b&3|(b&8)>>1;this.timer_divider_shift=7===b?0:b+1;break;case 896:dbg_log("timer initial: "+h(b>>>0,8),LOG_APIC);this.timer_initial_count=b>>>0;this.timer_current_count=
b>>>0;this.next_tick=v86.microtick();this.timer_active=!0;break;case 912:dbg_log("timer current: "+h(b>>>0,8),LOG_APIC);dbg_assert(!1,"read-only register");break;default:dbg_log("APIC write32 "+h(a)+" <- "+h(b>>>0,8),LOG_APIC),dbg_assert(!1)}};
APIC.prototype.timer=function(a){if(0===this.timer_current_count)return 100;const b=TSC_RATE/(1<<this.timer_divider_shift);a=(a-this.next_tick)*b>>>0;this.next_tick+=a/b;this.timer_current_count-=a;0>=this.timer_current_count&&(a=this.lvt_timer&APIC_TIMER_MODE_MASK,a===APIC_TIMER_MODE_PERIODIC?(this.timer_current_count%=this.timer_initial_count,0>=this.timer_current_count&&(this.timer_current_count+=this.timer_initial_count),dbg_assert(0!==this.timer_current_count),0===(this.lvt_timer&IOAPIC_CONFIG_MASKED)&&
this.deliver(this.lvt_timer&255,IOAPIC_DELIVERY_FIXED,!1)):a===APIC_TIMER_MODE_ONE_SHOT&&(this.timer_current_count=0,dbg_log("APIC timer one shot end",LOG_APIC),0===(this.lvt_timer&IOAPIC_CONFIG_MASKED)&&this.deliver(this.lvt_timer&255,IOAPIC_DELIVERY_FIXED,!1)));return Math.max(0,this.timer_current_count/b)};APIC.prototype.route=function(a,b,c,d,e){this.deliver(a,b,c)};
APIC.prototype.deliver=function(a,b,c){APIC_LOG_VERBOSE&&dbg_log("Deliver "+h(a,2)+" mode="+b+" level="+c,LOG_APIC);b!==IOAPIC_DELIVERY_INIT&&b!==IOAPIC_DELIVERY_NMI&&((16>a||255===a)&&dbg_assert(!1,"TODO: Invalid vector"),this.register_get_bit(this.irr,a)?dbg_log("Not delivered: irr already set, vector="+h(a,2),LOG_APIC):(this.register_set_bit(this.irr,a),c?this.register_set_bit(this.tmr,a):this.register_clear_bit(this.tmr,a),this.check_vector()))};
APIC.prototype.highest_irr=function(){var a=this.register_get_highest_bit(this.irr);dbg_assert(255!==a);dbg_assert(16<=a||-1===a);return a};APIC.prototype.highest_isr=function(){var a=this.register_get_highest_bit(this.isr);dbg_assert(255!==a);dbg_assert(16<=a||-1===a);return a};
APIC.prototype.check_vector=function(){var a=this.highest_irr();if(-1!==a){var b=this.highest_isr();b>=a?APIC_LOG_VERBOSE&&dbg_log("Higher isr, isr="+h(b)+" irr="+h(a),LOG_APIC):(a&240)<=(this.tpr&240)?APIC_LOG_VERBOSE&&dbg_log("Higher tpr, tpr="+h(this.tpr&240)+" irr="+h(a),LOG_APIC):this.cpu.handle_irqs()}};
APIC.prototype.acknowledge_irq=function(){var a=this.highest_irr();if(-1!==a){var b=this.highest_isr();b>=a?APIC_LOG_VERBOSE&&dbg_log("Higher isr, isr="+h(b)+" irr="+h(a),LOG_APIC):(a&240)<=(this.tpr&240)?APIC_LOG_VERBOSE&&dbg_log("Higher tpr, tpr="+h(this.tpr&240)+" irr="+h(a),LOG_APIC):(this.register_clear_bit(this.irr,a),this.register_set_bit(this.isr,a),APIC_LOG_VERBOSE&&dbg_log("Calling vector "+h(a),LOG_APIC),this.cpu.pic_call_irq(a),this.check_vector())}};
APIC.prototype.get_state=function(){var a=[];a[0]=this.apic_id;a[1]=this.timer_divider;a[2]=this.timer_divider_shift;a[3]=this.timer_initial_count;a[4]=this.timer_current_count;a[5]=this.next_tick;a[6]=this.lvt_timer;a[7]=this.lvt_perf_counter;a[8]=this.lvt_int0;a[9]=this.lvt_int1;a[10]=this.lvt_error;a[11]=this.tpr;a[12]=this.icr0;a[13]=this.icr1;a[14]=this.irr;a[15]=this.isr;a[16]=this.tmr;a[17]=this.spurious_vector;a[18]=this.destination_format;a[19]=this.local_destination;a[20]=this.error;a[21]=
this.read_error;return a};
APIC.prototype.set_state=function(a){this.apic_id=a[0];this.timer_divider=a[1];this.timer_divider_shift=a[2];this.timer_initial_count=a[3];this.timer_current_count=a[4];this.next_tick=a[5];this.lvt_timer=a[6];this.lvt_perf_counter=a[7];this.lvt_int0=a[8];this.lvt_int1=a[9];this.lvt_error=a[10];this.tpr=a[11];this.icr0=a[12];this.icr1=a[13];this.irr=a[14];this.isr=a[15];this.tmr=a[16];this.spurious_vector=a[17];this.destination_format=a[18];this.local_destination=a[19];this.error=a[20];this.read_error=
a[21]};APIC.prototype.register_get_bit=function(a,b){dbg_assert(0<=b&&256>b);return a[b>>5]>>(b&31)&1};APIC.prototype.register_set_bit=function(a,b){dbg_assert(0<=b&&256>b);a[b>>5]|=1<<(b&31)};APIC.prototype.register_clear_bit=function(a,b){dbg_assert(0<=b&&256>b);a[b>>5]&=~(1<<(b&31))};APIC.prototype.register_get_highest_bit=function(a){for(var b=7;0<=b;b--){var c=a[b];if(c)return v86util.int_log2(c>>>0)|b<<5}return-1};var IOAPIC_ADDRESS=4273995776,IOREGSEL=0,IOWIN=16,IOAPIC_IRQ_COUNT=24,IOAPIC_ID=0,IOAPIC_CONFIG_TRIGGER_MODE_LEVEL=32768,IOAPIC_CONFIG_MASKED=65536,IOAPIC_CONFIG_DELIVS=4096,IOAPIC_CONFIG_REMOTE_IRR=16384,IOAPIC_CONFIG_READONLY_MASK=IOAPIC_CONFIG_REMOTE_IRR|IOAPIC_CONFIG_DELIVS|4294836224,IOAPIC_DELIVERY_FIXED=0,IOAPIC_DELIVERY_LOWEST_PRIORITY=1,IOAPIC_DELIVERY_NMI=4,IOAPIC_DELIVERY_INIT=5;
function IOAPIC(a){this.cpu=a;this.ioredtbl_config=new Int32Array(IOAPIC_IRQ_COUNT);this.ioredtbl_destination=new Int32Array(IOAPIC_IRQ_COUNT);for(var b=0;b<this.ioredtbl_config.length;b++)this.ioredtbl_config[b]=IOAPIC_CONFIG_MASKED;this.ioregsel=0;this.ioapic_id=IOAPIC_ID;this.irq_value=this.irr=0;dbg_assert(32<=MMAP_BLOCK_SIZE);a.io.mmap_register(IOAPIC_ADDRESS,MMAP_BLOCK_SIZE,c=>{c=c-IOAPIC_ADDRESS|0;if(c>=IOWIN&&c<IOWIN+4)return c-=IOWIN,dbg_log("ioapic read8 byte "+c+" "+h(this.ioregsel),LOG_APIC),
this.read(this.ioregsel)>>8*c&255;dbg_log("Unexpected IOAPIC register read: "+h(c>>>0),LOG_APIC);dbg_assert(!1);return 0},(c,d)=>{dbg_assert(!1,"unsupported write8 from ioapic: "+h(c>>>0))},c=>{c=c-IOAPIC_ADDRESS|0;if(c===IOREGSEL)return this.ioregsel;if(c===IOWIN)return this.read(this.ioregsel);dbg_log("Unexpected IOAPIC register read: "+h(c>>>0),LOG_APIC);dbg_assert(!1);return 0},(c,d)=>{c=c-IOAPIC_ADDRESS|0;c===IOREGSEL?this.ioregsel=d:c===IOWIN?this.write(this.ioregsel,d):(dbg_log("Unexpected IOAPIC register write: "+
h(c>>>0)+" <- "+h(d>>>0,8),LOG_APIC),dbg_assert(!1))})}IOAPIC.prototype.remote_eoi=function(a){for(var b=0;b<IOAPIC_IRQ_COUNT;b++){var c=this.ioredtbl_config[b];(c&255)===a&&c&IOAPIC_CONFIG_REMOTE_IRR&&(dbg_log("Clear remote IRR for irq="+h(b),LOG_APIC),this.ioredtbl_config[b]&=~IOAPIC_CONFIG_REMOTE_IRR,this.check_irq(b))}};
IOAPIC.prototype.check_irq=function(a){var b=1<<a;if(0!==(this.irr&b)){var c=this.ioredtbl_config[a];if(0===(c&IOAPIC_CONFIG_MASKED)){var d=c>>8&7,e=c>>11&1,g=c&255,f=this.ioredtbl_destination[a]>>>24,k=(c&IOAPIC_CONFIG_TRIGGER_MODE_LEVEL)===IOAPIC_CONFIG_TRIGGER_MODE_LEVEL;if(0===(c&IOAPIC_CONFIG_TRIGGER_MODE_LEVEL))this.irr&=~b;else if(this.ioredtbl_config[a]|=IOAPIC_CONFIG_REMOTE_IRR,c&IOAPIC_CONFIG_REMOTE_IRR){dbg_log("No route: level interrupt and remote IRR still set",LOG_APIC);return}d===IOAPIC_DELIVERY_FIXED||
d===IOAPIC_DELIVERY_LOWEST_PRIORITY?this.cpu.devices.apic.route(g,d,k,f,e):dbg_assert(!1,"TODO");this.ioredtbl_config[a]&=~IOAPIC_CONFIG_DELIVS}}};IOAPIC.prototype.set_irq=function(a){if(a>=IOAPIC_IRQ_COUNT)dbg_assert(!1,"Bad irq: "+a,LOG_APIC);else{var b=1<<a;0===(this.irq_value&b)&&(APIC_LOG_VERBOSE&&dbg_log("apic set irq "+a,LOG_APIC),this.irq_value|=b,(this.ioredtbl_config[a]&(IOAPIC_CONFIG_TRIGGER_MODE_LEVEL|IOAPIC_CONFIG_MASKED))!==IOAPIC_CONFIG_MASKED&&(this.irr|=b,this.check_irq(a)))}};
IOAPIC.prototype.clear_irq=function(a){if(a>=IOAPIC_IRQ_COUNT)dbg_assert(!1,"Bad irq: "+a,LOG_APIC);else{var b=1<<a;(this.irq_value&b)===b&&(this.irq_value&=~b,this.ioredtbl_config[a]&IOAPIC_CONFIG_TRIGGER_MODE_LEVEL&&(this.irr&=~b))}};
IOAPIC.prototype.read=function(a){if(0===a)return dbg_log("IOAPIC Read id",LOG_APIC),this.ioapic_id<<24;if(1===a)return dbg_log("IOAPIC Read version",LOG_APIC),17|IOAPIC_IRQ_COUNT-1<<16;if(2===a)return dbg_log("IOAPIC Read arbitration id",LOG_APIC),this.ioapic_id<<24;if(16<=a&&a<16+2*IOAPIC_IRQ_COUNT){var b=a-16>>1;a&1?(a=this.ioredtbl_destination[b],dbg_log("IOAPIC Read destination irq="+h(b)+" -> "+h(a,8),LOG_APIC)):(a=this.ioredtbl_config[b],dbg_log("IOAPIC Read config irq="+h(b)+" -> "+h(a,8),
LOG_APIC));return a}dbg_log("IOAPIC register read outside of range "+h(a),LOG_APIC);dbg_assert(!1);return 0};
IOAPIC.prototype.write=function(a,b){if(0===a)this.ioapic_id=b>>>24&15;else if(1===a||2===a)dbg_log("Invalid write: "+a,LOG_APIC);else if(16<=a&&a<16+2*IOAPIC_IRQ_COUNT){var c=a-16>>1;if(a&1)this.ioredtbl_destination[c]=b&4278190080,dbg_log("Write destination "+h(b>>>0,8)+" irq="+h(c)+" dest="+h(b>>>24,2),LOG_APIC);else{this.ioredtbl_config[c]=b&~IOAPIC_CONFIG_READONLY_MASK|this.ioredtbl_config[c]&IOAPIC_CONFIG_READONLY_MASK;a=b&255;var d=b>>8&7,e=b>>11&1,g=b>>15&1,f=b>>16&1;dbg_log("Write config "+
h(b>>>0,8)+" irq="+h(c)+" vector="+h(a,2)+" deliverymode="+DELIVERY_MODES[d]+" destmode="+DESTINATION_MODES[e]+" is_level="+g+" disabled="+f,LOG_APIC);this.check_irq(c)}}else dbg_log("IOAPIC register write outside of range "+h(a)+": "+h(b>>>0,8),LOG_APIC),dbg_assert(!1)};IOAPIC.prototype.get_state=function(){var a=[];a[0]=this.ioredtbl_config;a[1]=this.ioredtbl_destination;a[2]=this.ioregsel;a[3]=this.ioapic_id;a[4]=this.irr;a[5]=this.irq_value;return a};
IOAPIC.prototype.set_state=function(a){this.ioredtbl_config=a[0];this.ioredtbl_destination=a[1];this.ioregsel=a[2];this.ioapic_id=a[3];this.irr=a[4];this.irq_value=a[5]};var STATE_VERSION=6,STATE_MAGIC=-2039052682,STATE_INDEX_MAGIC=0,STATE_INDEX_VERSION=1,STATE_INDEX_TOTAL_LEN=2,STATE_INDEX_INFO_LEN=3,STATE_INFO_BLOCK_START=16;const ZSTD_MAGIC=4247762216;function StateLoadError(a){this.message=a}StateLoadError.prototype=Error();const CONSTRUCTOR_TABLE={Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};
function save_object(a,b){if("object"!==typeof a||null===a)return dbg_assert("function"!==typeof a),a;if(a instanceof Array)return a.map(g=>save_object(g,b));a.constructor===Object&&(console.log(a),dbg_assert(a.constructor!==Object,"Expected non-object"));if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);a=a.constructor.name.replace("bound ","");dbg_assert(CONSTRUCTOR_TABLE[a]);return{__state_type__:a,buffer_id:b.push(c)-1}}DEBUG&&!a.get_state&&console.log("Object without get_state: ",
a);c=a.get_state();a=[];for(var d=0;d<c.length;d++){var e=c[d];dbg_assert("function"!==typeof e);a[d]=save_object(e,b)}return a}function restore_buffers(a,b){if("object"!==typeof a||null===a)return dbg_assert("function"!==typeof a),a;if(a instanceof Array){for(var c=0;c<a.length;c++)a[c]=restore_buffers(a[c],b);return a}c=a.__state_type__;dbg_assert(void 0!==c);const d=CONSTRUCTOR_TABLE[c];dbg_assert(d,"Unkown type: "+c);return new d(b[a.buffer_id])}
CPU.prototype.save_state=function(){for(var a=[],b=save_object(this,a),c=[],d=0,e=0;e<a.length;e++){var g=a[e].byteLength;c[e]={offset:d,length:g};d+=g;d=d+3&-4}b=JSON.stringify({buffer_infos:c,state:b});b=(new TextEncoder).encode(b);e=STATE_INFO_BLOCK_START+b.length;e=e+3&-4;var f=e+d;d=new ArrayBuffer(f);var k=new Int32Array(d,0,STATE_INFO_BLOCK_START/4);(new Uint8Array(d,STATE_INFO_BLOCK_START,b.length)).set(b);g=new Uint8Array(d,e);k[STATE_INDEX_MAGIC]=STATE_MAGIC;k[STATE_INDEX_VERSION]=STATE_VERSION;
k[STATE_INDEX_TOTAL_LEN]=f;k[STATE_INDEX_INFO_LEN]=b.length;for(e=0;e<a.length;e++)f=a[e],dbg_assert(f.constructor===Uint8Array),g.set(f,c[e].offset);dbg_log("State: json size "+(b.byteLength>>10)+"k");dbg_log("State: Total buffers size "+(g.byteLength>>10)+"k");return d};
CPU.prototype.restore_state=function(a){function b(t,r){const q=t.length;if(q<STATE_INFO_BLOCK_START)throw new StateLoadError("Invalid length: "+q);t=new Int32Array(t.buffer,t.byteOffset,4);if(t[STATE_INDEX_MAGIC]!==STATE_MAGIC)throw new StateLoadError("Invalid header: "+h(t[STATE_INDEX_MAGIC]>>>0));if(t[STATE_INDEX_VERSION]!==STATE_VERSION)throw new StateLoadError("Version mismatch: dump="+t[STATE_INDEX_VERSION]+" we="+STATE_VERSION);if(r&&t[STATE_INDEX_TOTAL_LEN]!==q)throw new StateLoadError("Length doesn't match header: real="+
q+" header="+t[STATE_INDEX_TOTAL_LEN]);return t[STATE_INDEX_INFO_LEN]}function c(t){t=(new TextDecoder).decode(t);return JSON.parse(t)}a=new Uint8Array(a);if((new Uint32Array(a.buffer,0,1))[0]===ZSTD_MAGIC){var d=this.zstd_create_ctx(a.length);(new Uint8Array(this.wasm_memory.buffer,this.zstd_get_src_ptr(d),a.length)).set(a);var e=this.zstd_read(d,16),g=new Uint8Array(this.wasm_memory.buffer,e,16),f=b(g,!1);this.zstd_read_free(e,16);e=this.zstd_read(d,f);g=new Uint8Array(this.wasm_memory.buffer,e,
f);g=c(g);this.zstd_read_free(e,f);e=g.state;var k=g.buffer_infos;g=[];f=STATE_INFO_BLOCK_START+f;for(var m of k){k=(f+3&-4)-f;if(1048576<m.length){var l=this.zstd_read(d,k);this.zstd_read_free(l,k);l=new Uint8Array(m.length);g.push(l.buffer);for(var n=0;n<m.length;){var p=m.length-n;dbg_assert(0<=p);p=Math.min(p,1048576);const t=this.zstd_read(d,p);l.set(new Uint8Array(this.wasm_memory.buffer,t,p),n);this.zstd_read_free(t,p);n+=p}}else l=this.zstd_read(d,k+m.length),n=l+k,g.push(this.wasm_memory.buffer.slice(n,
n+m.length)),this.zstd_read_free(l,k+m.length);f+=k+m.length}e=restore_buffers(e,g);this.set_state(e);this.zstd_free_ctx(d)}else{d=b(a,!0);if(0>d||d+12>=a.length)throw new StateLoadError("Invalid info block length: "+d);m=a.subarray(STATE_INFO_BLOCK_START,STATE_INFO_BLOCK_START+d);e=c(m);m=e.state;e=e.buffer_infos;let t=STATE_INFO_BLOCK_START+d;t=t+3&-4;d=e.map(r=>{const q=t+r.offset;return a.buffer.slice(q,q+r.length)});m=restore_buffers(m,d);this.set_state(m)}};const NE2K_LOG_VERBOSE=!1,NE2K_LOG_PACKETS=!1;
var E8390_CMD=0,EN0_CLDALO=1,EN0_STARTPG=1,EN0_CLDAHI=2,EN0_STOPPG=2,EN0_BOUNDARY=3,EN0_TSR=4,EN0_TPSR=4,EN0_NCR=5,EN0_TCNTLO=5,EN0_FIFO=6,EN0_TCNTHI=6,EN0_ISR=7,EN0_CRDALO=8,EN0_RSARLO=8,EN0_CRDAHI=9,EN0_RSARHI=9,EN0_RCNTLO=10,EN0_RCNTHI=11,EN0_RSR=12,EN0_RXCR=12,EN0_TXCR=13,EN0_COUNTER0=13,EN0_DCFG=14,EN0_COUNTER1=14,EN0_IMR=15,EN0_COUNTER2=15,NE_DATAPORT=16,NE_RESET=31,ENISR_RX=1,ENISR_TX=2,ENISR_RX_ERR=4,ENISR_TX_ERR=8,ENISR_OVER=16,ENISR_COUNTERS=32,ENISR_RDC=64,ENISR_RESET=128,ENISR_ALL=63,
ENRSR_RXOK=1,START_PAGE=64,START_RX_PAGE=76,STOP_PAGE=128;
function translate_mac_address(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(dbg_log("Replace mac in eth destination field",LOG_NET),a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(dbg_log("Replace mac in eth source field",LOG_NET),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)dbg_log("Expected ipv4.version==4 but got: "+
d,LOG_NET);else{if(dbg_assert(5===(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];dbg_log("udp srcport="+d+" dstport="+e+" checksum="+h(a[6]<<8|a[7],4),LOG_NET);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)dbg_log("dhcp packet didn't match magic: "+h(e,8));else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(dbg_log("Replace mac in dhcp.chaddr",LOG_NET),d[28]=c[0],d[29]=
c[1],d[30]=c[2],d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const g=d[e++];if(255===g)break;const f=d[e++];61===g&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(dbg_log("Replace mac in dhcp.clientidentifier",LOG_NET),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=f}}}else 2054===d&&(a=a.subarray(14),dbg_log("arp oper="+a[7]+" "+format_mac(a.subarray(8,14))+" "+format_mac(a.subarray(18,
24)),LOG_NET),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(dbg_log("Replace mac in arp.sha",LOG_NET),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function format_mac(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}
function dump_packet(a,b){const c=a[12]<<8|a[13]<<0;if(2048===c){var d=a.subarray(14);const f=d[2]<<8|d[3];var e=d[9];if(17===e){var g=d.subarray(20);d=g[0]<<8|g[1];e=g[2]<<8|g[3];const k=g[6]<<8|g[7];67===d||67===e?(g=g.subarray(8).subarray(28,34),dbg_log(b+" len="+a.length+" ethertype="+h(c)+" ipv4.len="+f+" ipv4.proto="+h(a[23])+" udp.srcport="+d+" udp.dstport="+e+" udp.chksum="+h(k,4)+" dhcp.chaddr="+format_mac(g))):dbg_log(b+" len="+a.length+" ethertype="+h(c)+" ipv4.len="+f+" ipv4.proto="+h(a[23])+
" udp.srcport="+d+" udp.dstport="+e+" udp.chksum="+h(k,4))}else 1!==e&&dbg_log(b+" len="+a.length+" ethertype="+h(c)+" ipv4.len="+f+" ipv4.proto="+h(a[23]))}else a.subarray(14),dbg_log(b+" len="+a.length+" ethertype="+h(c)+" arp");dbg_log(hex_dump(a))}
function Ne2k(a,b,c,d){this.cpu=a;this.pci=a.devices.pci;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net0-receive",function(e){this.receive(e)},this);this.port=768;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=40;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=
this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;dbg_log("Mac: "+format_mac(this.mac),LOG_NET);this.rsar=0;this.pstart=START_PAGE;this.pstop=STOP_PAGE;this.boundary=this.curpg=START_RX_PAGE;b=a.io;b.register_read(this.port|
E8390_CMD,this,function(){dbg_log("Read cmd",LOG_NET);return this.cr});b.register_write(this.port|E8390_CMD,this,function(e){this.cr=e;dbg_log("Write command: "+h(e,2)+" newpg="+(this.cr>>6)+" txcr="+h(this.txcr,2),LOG_NET);this.cr&1||(e&24&&0===this.rcnt&&this.do_interrupt(ENISR_RDC),e&4&&(e=this.tpsr<<8,e=this.memory.subarray(e,e+this.tcnt),NE2K_LOG_PACKETS&&dump_packet(e,"send"),this.mac_address_in_state&&(e=new Uint8Array(e),translate_mac_address(e,this.mac_address_in_state,this.mac)),this.bus.send("net0-send",
e),this.bus.send("eth-transmit-end",[e.length]),this.cr&=-5,this.do_interrupt(ENISR_TX),dbg_log("Command: Transfer. length="+h(e.byteLength),LOG_NET)))});b.register_read(this.port|EN0_COUNTER0,this,function(){dbg_log("Read counter0",LOG_NET);return 0});b.register_read(this.port|EN0_COUNTER1,this,function(){dbg_log("Read8 counter1",LOG_NET);return 0},function(){dbg_log("Read16 counter1",LOG_NET);return 0});b.register_read(this.port|EN0_COUNTER2,this,function(){dbg_log("Read counter2",LOG_NET);return 0});
b.register_read(this.port|NE_RESET,this,function(){this.get_page();dbg_log("Read reset",LOG_NET);this.do_interrupt(ENISR_RESET);return 0});b.register_write(this.port|NE_RESET,this,function(e){this.get_page();dbg_log("Write reset: "+h(e,2),LOG_NET)});b.register_read(this.port|EN0_STARTPG,this,function(){var e=this.get_page();if(0===e)return this.pstart;if(1===e)return dbg_log("Read pg1/01 (mac[0])",LOG_NET),this.mac[0];if(2===e)return this.pstart;dbg_log("Read pg"+e+"/01");dbg_assert(!1);return 0});
b.register_write(this.port|EN0_STARTPG,this,function(e){var g=this.get_page();0===g?(dbg_log("start page: "+h(e,2),LOG_NET),this.pstart=e):1===g?(dbg_log("mac[0] = "+h(e),LOG_NET),this.mac[0]=e):3===g?dbg_log("Unimplemented: Write pg3/01 (9346CR): "+h(e),LOG_NET):(dbg_log("Write pg"+g+"/01: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_STOPPG,this,function(){var e=this.get_page();if(0===e)return this.pstop;if(1===e)return dbg_log("Read pg1/02 (mac[1])",LOG_NET),this.mac[1];if(2===
e)return this.pstop;dbg_log("Read pg"+e+"/02",LOG_NET);dbg_assert(!1);return 0});b.register_write(this.port|EN0_STOPPG,this,function(e){var g=this.get_page();0===g?(dbg_log("stop page: "+h(e,2),LOG_NET),e>this.memory.length>>8&&(e=this.memory.length>>8,dbg_log("XXX: Adjusting stop page to "+h(e),LOG_NET)),this.pstop=e):1===g?(dbg_log("mac[1] = "+h(e),LOG_NET),this.mac[1]=e):(dbg_log("Write pg"+g+"/02: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_ISR,this,function(){var e=this.get_page();
if(0===e)return dbg_log("Read isr: "+h(this.isr,2),LOG_NET),this.isr;if(1===e)return dbg_log("Read curpg: "+h(this.curpg,2),LOG_NET),this.curpg;dbg_assert(!1)});b.register_write(this.port|EN0_ISR,this,function(e){var g=this.get_page();0===g?(dbg_log("Write isr: "+h(e,2),LOG_NET),this.isr&=~e,this.update_irq()):1===g?(dbg_log("Write curpg: "+h(e,2),LOG_NET),this.curpg=e):dbg_assert(!1)});b.register_write(this.port|EN0_TXCR,this,function(e){var g=this.get_page();0===g?(this.txcr=e,dbg_log("Write tx config: "+
h(e,2),LOG_NET)):dbg_log("Unimplemented: Write pg"+g+"/0d "+h(e,2),LOG_NET)});b.register_write(this.port|EN0_DCFG,this,function(e){var g=this.get_page();0===g?(dbg_log("Write data configuration: "+h(e,2),LOG_NET),this.dcfg=e):dbg_log("Unimplemented: Write pg"+g+"/0e "+h(e,2),LOG_NET)});b.register_read(this.port|EN0_RCNTLO,this,function(){if(0===this.get_page())return dbg_log("Read pg0/0a",LOG_NET),80;dbg_assert(!1,"TODO");return 0});b.register_write(this.port|EN0_RCNTLO,this,function(e){var g=this.get_page();
0===g?(dbg_log("Write remote byte count low: "+h(e,2),LOG_NET),this.rcnt=this.rcnt&65280|e&255):dbg_log("Unimplemented: Write pg"+g+"/0a "+h(e,2),LOG_NET)});b.register_read(this.port|EN0_RCNTHI,this,function(){if(0===this.get_page())return dbg_log("Read pg0/0b",LOG_NET),67;dbg_assert(!1,"TODO");return 0});b.register_write(this.port|EN0_RCNTHI,this,function(e){var g=this.get_page();0===g?(dbg_log("Write remote byte count high: "+h(e,2),LOG_NET),this.rcnt=this.rcnt&255|e<<8&65280):dbg_log("Unimplemented: Write pg"+
g+"/0b "+h(e,2),LOG_NET)});b.register_read(this.port|EN0_RSARLO,this,function(){var e=this.get_page();if(0===e)return dbg_log("Read remote start address low",LOG_NET),this.rsar&255;dbg_log("Unimplemented: Read pg"+e+"/08",LOG_NET);dbg_assert(!1)});b.register_write(this.port|EN0_RSARLO,this,function(e){var g=this.get_page();0===g?(dbg_log("Write remote start address low: "+h(e,2),LOG_NET),this.rsar=this.rsar&65280|e&255):dbg_log("Unimplemented: Write pg"+g+"/08 "+h(e,2),LOG_NET)});b.register_read(this.port|
EN0_RSARHI,this,function(){var e=this.get_page();if(0===e)return dbg_log("Read remote start address high",LOG_NET),this.rsar>>8&255;dbg_log("Unimplemented: Read pg"+e+"/09",LOG_NET);dbg_assert(!1)});b.register_write(this.port|EN0_RSARHI,this,function(e){var g=this.get_page();0===g?(dbg_log("Write remote start address low: "+h(e,2),LOG_NET),this.rsar=this.rsar&255|e<<8&65280):dbg_log("Unimplemented: Write pg"+g+"/09 "+h(e,2),LOG_NET)});b.register_write(this.port|EN0_IMR,this,function(e){var g=this.get_page();
0===g?(dbg_log("Write interrupt mask register: "+h(e,2)+" isr="+h(this.isr,2),LOG_NET),this.imr=e,this.update_irq()):dbg_log("Unimplemented: Write pg"+g+"/0f "+h(e,2),LOG_NET)});b.register_read(this.port|EN0_BOUNDARY,this,function(){var e=this.get_page();if(0===e)return dbg_log("Read boundary: "+h(this.boundary,2),LOG_NET),this.boundary;if(1===e)return dbg_log("Read pg1/03 (mac[2])",LOG_NET),this.mac[2];3===e?dbg_log("Unimplemented: Read pg3/03 (CONFIG0)",LOG_NET):(dbg_log("Read pg"+e+"/03",LOG_NET),
dbg_assert(!1));return 0});b.register_write(this.port|EN0_BOUNDARY,this,function(e){var g=this.get_page();0===g?(dbg_log("Write boundary: "+h(e,2),LOG_NET),this.boundary=e):1===g?(dbg_log("mac[2] = "+h(e),LOG_NET),this.mac[2]=e):(dbg_log("Write pg"+g+"/03: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_TSR,this,function(){var e=this.get_page();if(0===e)return this.tsr;if(1===e)return dbg_log("Read pg1/04 (mac[3])",LOG_NET),this.mac[3];dbg_log("Read pg"+e+"/04",LOG_NET);dbg_assert(!1);
return 0});b.register_write(this.port|EN0_TPSR,this,function(e){var g=this.get_page();0===g?(dbg_log("Write tpsr: "+h(e,2),LOG_NET),this.tpsr=e):1===g?(dbg_log("mac[3] = "+h(e),LOG_NET),this.mac[3]=e):(dbg_log("Write pg"+g+"/04: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_TCNTLO,this,function(){var e=this.get_page();if(0===e)return dbg_log("Unimplemented: Read pg0/05 (NCR: Number of Collisions Register)",LOG_NET),0;if(1===e)return dbg_log("Read pg1/05 (mac[4])",LOG_NET),this.mac[4];
3===e?dbg_log("Unimplemented: Read pg3/05 (CONFIG2)",LOG_NET):(dbg_log("Read pg"+e+"/05",LOG_NET),dbg_assert(!1));return 0});b.register_write(this.port|EN0_TCNTLO,this,function(e){var g=this.get_page();0===g?(dbg_log("Write tcnt low: "+h(e,2),LOG_NET),this.tcnt=this.tcnt&-256|e):1===g?(dbg_log("mac[4] = "+h(e),LOG_NET),this.mac[4]=e):3===g?dbg_log("Unimplemented: Write pg3/05 (CONFIG2): "+h(e),LOG_NET):(dbg_log("Write pg"+g+"/05: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_TCNTHI,
this,function(){var e=this.get_page();if(0===e)return dbg_assert(!1,"TODO"),0;if(1===e)return dbg_log("Read pg1/06 (mac[5])",LOG_NET),this.mac[5];3===e?dbg_log("Unimplemented: Read pg3/06 (CONFIG3)",LOG_NET):(dbg_log("Read pg"+e+"/06",LOG_NET),dbg_assert(!1));return 0});b.register_write(this.port|EN0_TCNTHI,this,function(e){var g=this.get_page();0===g?(dbg_log("Write tcnt high: "+h(e,2),LOG_NET),this.tcnt=this.tcnt&255|e<<8):1===g?(dbg_log("mac[5] = "+h(e),LOG_NET),this.mac[5]=e):3===g?dbg_log("Unimplemented: Write pg3/06 (CONFIG3): "+
h(e),LOG_NET):(dbg_log("Write pg"+g+"/06: "+h(e),LOG_NET),dbg_assert(!1))});b.register_read(this.port|EN0_RSR,this,function(){var e=this.get_page();if(0===e)return 9;dbg_log("Unimplemented: Read pg"+e+"/0c",LOG_NET);dbg_assert(!1);return 0});b.register_write(this.port|EN0_RXCR,this,function(e){var g=this.get_page();0===g?(dbg_log("RX configuration reg write: "+h(e,2),LOG_NET),this.rxcr=e):dbg_log("Unimplemented: Write pg"+g+"/0c: "+h(e),LOG_NET)});b.register_read(this.port|NE_DATAPORT|0,this,this.data_port_read8,
this.data_port_read16,this.data_port_read32);b.register_write(this.port|NE_DATAPORT|0,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);a.devices.pci.register_device(this)}
Ne2k.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;a[9]=this.curpg;a[10]=this.boundary;a[11]=this.pstop;a[12]=this.rxcr;a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};
Ne2k.prototype.set_state=function(a){this.isr=a[0];this.imr=a[1];this.cr=a[2];this.dcfg=a[3];this.rcnt=a[4];this.tcnt=a[5];this.tpsr=a[6];this.rsar=a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&(this.mac_address_in_state=a[15],this.memory=a[16],dbg_log("Using mac address translation guest_os_mac="+format_mac(this.mac_address_in_state)+
" real_mac="+format_mac(this.mac),LOG_NET))};Ne2k.prototype.do_interrupt=function(a){dbg_log("Do interrupt "+h(a,2),LOG_NET);this.isr|=a;this.update_irq()};Ne2k.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};
Ne2k.prototype.data_port_write=function(a){NE2K_LOG_VERBOSE&&dbg_log("Write data port: data="+h(a&255,2)+" rsar="+h(this.rsar,4)+" rcnt="+h(this.rcnt,4),LOG_NET);if(16>=this.rsar||this.rsar>=START_PAGE<<8&&this.rsar<STOP_PAGE<<8)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(ENISR_RDC)};Ne2k.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};
Ne2k.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};Ne2k.prototype.data_port_read=function(){let a=0;this.rsar<STOP_PAGE<<8&&(a=this.memory[this.rsar]);NE2K_LOG_VERBOSE&&dbg_log("Read data port: data="+h(a,2)+" rsar="+h(this.rsar,4)+" rcnt="+h(this.rcnt,4),LOG_NET);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(ENISR_RDC);return a};
Ne2k.prototype.data_port_read8=function(){return this.data_port_read16()&255};Ne2k.prototype.data_port_read16=function(){return this.dcfg&1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};Ne2k.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};
Ne2k.prototype.receive=function(a){if(!(this.cr&1)&&(NE2K_LOG_PACKETS&&dump_packet(a,"receive"),this.bus.send("eth-receive-end",[a.length]),this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),translate_mac_address(a,this.mac,this.mac_address_in_state));var b=
this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),g=b+c,f=1+(c>>8),k=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;k<f&&0!==this.boundary?dbg_log("Buffer full, dropping packet pstart="+h(this.pstart)+" pstop="+h(this.pstop)+" curpg="+h(this.curpg)+" needed="+h(f)+" boundary="+h(this.boundary)+" available="+h(k),LOG_NET):(g>this.pstop<<8?(dbg_assert(60<=a.length),g=(this.pstop<<8)-d,dbg_assert(0<=g),this.memory.set(a.subarray(0,
g),d),this.memory.set(a.subarray(g),this.pstart<<8),dbg_log("rcv cut="+h(g),LOG_NET)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=ENRSR_RXOK,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,dbg_log("rcv offset="+h(b)+" len="+h(c)+" next="+h(e),LOG_NET),this.do_interrupt(ENISR_RX))}};Ne2k.prototype.get_page=function(){return this.cr>>6&3};var DSP_COPYRIGHT="COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.",DSP_NO_COMMAND=0,DSP_BUFSIZE=64,DSP_DACSIZE=65536,SB_DMA_BUFSIZE=65536,SB_DMA_BLOCK_SAMPLES=1024,SB_DMA0=0,SB_DMA1=1,SB_DMA3=3,SB_DMA5=5,SB_DMA6=6,SB_DMA7=7,SB_DMA_CHANNEL_8BIT=SB_DMA1,SB_DMA_CHANNEL_16BIT=SB_DMA5,SB_IRQ2=2,SB_IRQ5=5,SB_IRQ7=7,SB_IRQ10=10,SB_IRQ=SB_IRQ5,SB_IRQ_8BIT=1,SB_IRQ_16BIT=2,SB_IRQ_MIDI=1,SB_IRQ_MPU=4,DSP_COMMAND_SIZES=new Uint8Array(256),DSP_COMMAND_HANDLERS=[],MIXER_READ_HANDLERS=[],MIXER_WRITE_HANDLERS=[],
MIXER_REGISTER_IS_LEGACY=new Uint8Array(256),FM_HANDLERS=[];
function SB16(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ByteQueue(DSP_BUFSIZE);this.read_buffer=new ByteQueue(DSP_BUFSIZE);this.read_buffer_lastvalue=0;this.command=DSP_NO_COMMAND;this.mixer_current_address=this.command_size=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new FloatQueue(DSP_DACSIZE),new FloatQueue(DSP_DACSIZE)];this.dma=a.devices.dma;
this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=SB_DMA1;this.dma_channel_16bit=SB_DMA5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(SB_DMA_BUFSIZE);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new v86util.SyncBuffer(this.dma_buffer);
this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ByteQueue(DSP_BUFSIZE);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=SB_IRQ5;this.irq_triggered=new Uint8Array(16);a.io.register_read_consecutive(544,this,this.port2x0_read,this.port2x1_read,
this.port2x2_read,this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);a.io.register_read_consecutive(548,this,this.port2x4_read,this.port2x5_read);a.io.register_read(550,this,this.port2x6_read);a.io.register_read(551,this,this.port2x7_read);a.io.register_read(552,this,this.port2x8_read);a.io.register_read(553,this,this.port2x9_read);a.io.register_read(554,this,this.port2xA_read);a.io.register_read(555,this,this.port2xB_read);a.io.register_read(556,this,
this.port2xC_read);a.io.register_read(557,this,this.port2xD_read);a.io.register_read_consecutive(558,this,this.port2xE_read,this.port2xF_read);a.io.register_write_consecutive(544,this,this.port2x0_write,this.port2x1_write,this.port2x2_write,this.port2x3_write);a.io.register_write_consecutive(904,this,this.port2x0_write,this.port2x1_write);a.io.register_write_consecutive(548,this,this.port2x4_write,this.port2x5_write);a.io.register_write(550,this,this.port2x6_write);a.io.register_write(551,this,this.port2x7_write);
a.io.register_write_consecutive(552,this,this.port2x8_write,this.port2x9_write);a.io.register_write(554,this,this.port2xA_write);a.io.register_write(555,this,this.port2xB_write);a.io.register_write(556,this,this.port2xC_write);a.io.register_write(557,this,this.port2xD_write);a.io.register_write(558,this,this.port2xE_write);a.io.register_write(559,this,this.port2xF_write);a.io.register_read_consecutive(816,this,this.port3x0_read,this.port3x1_read);a.io.register_write_consecutive(816,this,this.port3x0_write,
this.port3x1_write);this.dma.on_unmask(this.dma_on_unmask,this);b.register("dac-request-data",function(){this.dac_handle_request()},this);b.register("speaker-has-initialized",function(){this.mixer_reset()},this);b.send("speaker-confirm-initialized");this.dsp_reset()}
SB16.prototype.dsp_reset=function(){this.write_buffer.clear();this.read_buffer.clear();this.command=DSP_NO_COMMAND;this.command_size=0;this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers[0].clear();this.dac_buffers[1].clear();this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_autoinit=!1;this.dma_buffer_uint8.fill(0);this.dma_paused=this.dma_waiting_transfer=
!1;this.e2_value=170;this.e2_count=0;this.sampling_rate=22050;this.bytes_per_sample=1;this.lower_irq(SB_IRQ_8BIT);this.irq_triggered.fill(0);this.asp_registers.fill(0);this.asp_registers[5]=1;this.asp_registers[9]=248};
SB16.prototype.get_state=function(){var a=[];a[2]=this.read_buffer_lastvalue;a[3]=this.command;a[4]=this.command_size;a[5]=this.mixer_current_address;a[6]=this.mixer_registers;a[7]=this.dummy_speaker_enabled;a[8]=this.test_register;a[9]=this.dsp_highspeed;a[10]=this.dsp_stereo;a[11]=this.dsp_16bit;a[12]=this.dsp_signed;a[15]=this.dma_sample_count;a[16]=this.dma_bytes_count;a[17]=this.dma_bytes_left;a[18]=this.dma_bytes_block;a[19]=this.dma_irq;a[20]=this.dma_channel;a[21]=this.dma_channel_8bit;a[22]=
this.dma_channel_16bit;a[23]=this.dma_autoinit;a[24]=this.dma_buffer_uint8;a[25]=this.dma_waiting_transfer;a[26]=this.dma_paused;a[27]=this.sampling_rate;a[28]=this.bytes_per_sample;a[29]=this.e2_value;a[30]=this.e2_count;a[31]=this.asp_registers;a[33]=this.mpu_read_buffer_last_value;a[34]=this.irq;a[35]=this.irq_triggered;return a};
SB16.prototype.set_state=function(a){this.read_buffer_lastvalue=a[2];this.command=a[3];this.command_size=a[4];this.mixer_current_address=a[5];this.mixer_registers=a[6];this.mixer_full_update();this.dummy_speaker_enabled=a[7];this.test_register=a[8];this.dsp_highspeed=a[9];this.dsp_stereo=a[10];this.dsp_16bit=a[11];this.dsp_signed=a[12];this.dma_sample_count=a[15];this.dma_bytes_count=a[16];this.dma_bytes_left=a[17];this.dma_bytes_block=a[18];this.dma_irq=a[19];this.dma_channel=a[20];this.dma_channel_8bit=
a[21];this.dma_channel_16bit=a[22];this.dma_autoinit=a[23];this.dma_buffer_uint8=a[24];this.dma_waiting_transfer=a[25];this.dma_paused=a[26];this.sampling_rate=a[27];this.bytes_per_sample=a[28];this.e2_value=a[29];this.e2_count=a[30];this.asp_registers=a[31];this.mpu_read_buffer_last_value=a[33];this.irq=a[34];this.irq_triggered=a[35];this.dma_buffer=this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=
new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new v86util.SyncBuffer(this.dma_buffer);this.dma_paused?this.bus.send("dac-disable"):this.bus.send("dac-enable")};SB16.prototype.port2x0_read=function(){dbg_log("220 read: fm music status port (unimplemented)",LOG_SB16);return 255};SB16.prototype.port2x1_read=function(){dbg_log("221 read: fm music data port (write only)",LOG_SB16);return 255};
SB16.prototype.port2x2_read=function(){dbg_log("222 read: advanced fm music status port (unimplemented)",LOG_SB16);return 255};SB16.prototype.port2x3_read=function(){dbg_log("223 read: advanced music data port (write only)",LOG_SB16);return 255};SB16.prototype.port2x4_read=function(){dbg_log("224 read: mixer address port",LOG_SB16);return this.mixer_current_address};SB16.prototype.port2x5_read=function(){dbg_log("225 read: mixer data port",LOG_SB16);return this.mixer_read(this.mixer_current_address)};
SB16.prototype.port2x6_read=function(){dbg_log("226 read: (write only)",LOG_SB16);return 255};SB16.prototype.port2x7_read=function(){dbg_log("227 read: undocumented",LOG_SB16);return 255};SB16.prototype.port2x8_read=function(){dbg_log("228 read: fm music status port (unimplemented)",LOG_SB16);return 255};SB16.prototype.port2x9_read=function(){dbg_log("229 read: fm music data port (write only)",LOG_SB16);return 255};
SB16.prototype.port2xA_read=function(){dbg_log("22A read: read data",LOG_SB16);this.read_buffer.length&&(this.read_buffer_lastvalue=this.read_buffer.shift());dbg_log(" <- "+this.read_buffer_lastvalue+" "+h(this.read_buffer_lastvalue)+" '"+String.fromCharCode(this.read_buffer_lastvalue)+"'",LOG_SB16);return this.read_buffer_lastvalue};SB16.prototype.port2xB_read=function(){dbg_log("22B read: undocumented",LOG_SB16);return 255};
SB16.prototype.port2xC_read=function(){dbg_log("22C read: write-buffer status",LOG_SB16);return 127};SB16.prototype.port2xD_read=function(){dbg_log("22D read: undocumented",LOG_SB16);return 255};SB16.prototype.port2xE_read=function(){dbg_log("22E read: read-buffer status / irq 8bit ack.",LOG_SB16);this.irq_triggered[SB_IRQ_8BIT]&&this.lower_irq(SB_IRQ_8BIT);return(this.read_buffer.length&&!this.dsp_highspeed)<<7|127};
SB16.prototype.port2xF_read=function(){dbg_log("22F read: irq 16bit ack",LOG_SB16);this.lower_irq(SB_IRQ_16BIT);return 0};SB16.prototype.port2x0_write=function(a){dbg_log("220 write: (unimplemented) fm register 0 address = "+h(a),LOG_SB16);this.fm_current_address0=0};SB16.prototype.port2x1_write=function(a){dbg_log("221 write: (unimplemented) fm register 0 data = "+h(a),LOG_SB16);var b=FM_HANDLERS[this.fm_current_address0];b||(b=this.fm_default_write);b.call(this,a,0,this.fm_current_address0)};
SB16.prototype.port2x2_write=function(a){dbg_log("222 write: (unimplemented) fm register 1 address = "+h(a),LOG_SB16);this.fm_current_address1=0};SB16.prototype.port2x3_write=function(a){dbg_log("223 write: (unimplemented) fm register 1 data ="+h(a),LOG_SB16);var b=FM_HANDLERS[this.fm_current_address1];b||(b=this.fm_default_write);b.call(this,a,1,this.fm_current_address1)};SB16.prototype.port2x4_write=function(a){dbg_log("224 write: mixer address = "+h(a),LOG_SB16);this.mixer_current_address=a};
SB16.prototype.port2x5_write=function(a){dbg_log("225 write: mixer data = "+h(a),LOG_SB16);this.mixer_write(this.mixer_current_address,a)};SB16.prototype.port2x6_write=function(a){dbg_log("226 write: reset = "+h(a),LOG_SB16);this.dsp_highspeed?(dbg_log(" -> exit highspeed",LOG_SB16),this.dsp_highspeed=!1):a&&(dbg_log(" -> reset",LOG_SB16),this.dsp_reset());this.read_buffer.clear();this.read_buffer.push(170)};SB16.prototype.port2x7_write=function(a){dbg_log("227 write: undocumented",LOG_SB16)};
SB16.prototype.port2x8_write=function(a){dbg_log("228 write: fm music register port (unimplemented)",LOG_SB16)};SB16.prototype.port2x9_write=function(a){dbg_log("229 write: fm music data port (unimplemented)",LOG_SB16)};SB16.prototype.port2xA_write=function(a){dbg_log("22A write: dsp read data port (read only)",LOG_SB16)};SB16.prototype.port2xB_write=function(a){dbg_log("22B write: undocumented",LOG_SB16)};
SB16.prototype.port2xC_write=function(a){dbg_log("22C write: write command/data",LOG_SB16);this.command===DSP_NO_COMMAND?(dbg_log("22C write: command = "+h(a),LOG_SB16),this.command=a,this.write_buffer.clear(),this.command_size=DSP_COMMAND_SIZES[a]):(dbg_log("22C write: data: "+h(a),LOG_SB16),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};SB16.prototype.port2xD_write=function(a){dbg_log("22D write: undocumented",LOG_SB16)};
SB16.prototype.port2xE_write=function(a){dbg_log("22E write: dsp read buffer status (read only)",LOG_SB16)};SB16.prototype.port2xF_write=function(a){dbg_log("22F write: undocumented",LOG_SB16)};SB16.prototype.port3x0_read=function(){dbg_log("330 read: mpu data",LOG_SB16);this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());dbg_log(" <- "+h(this.mpu_read_buffer_lastvalue),LOG_SB16);return this.mpu_read_buffer_lastvalue};
SB16.prototype.port3x0_write=function(a){dbg_log("330 write: mpu data (unimplemented) : "+h(a),LOG_SB16)};SB16.prototype.port3x1_read=function(){dbg_log("331 read: mpu status",LOG_SB16);return 0|128*!this.mpu_read_buffer.length};SB16.prototype.port3x1_write=function(a){dbg_log("331 write: mpu command: "+h(a),LOG_SB16);255==a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};
SB16.prototype.command_do=function(){var a=DSP_COMMAND_HANDLERS[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command=DSP_NO_COMMAND;this.command_size=0;this.write_buffer.clear()};SB16.prototype.dsp_default_handler=function(){dbg_log("Unhandled command: "+h(this.command),LOG_SB16)};function register_dsp_command(a,b,c){c||(c=SB16.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)DSP_COMMAND_SIZES[a[d]]=b,DSP_COMMAND_HANDLERS[a[d]]=c}
function any_first_digit(a){for(var b=[],c=0;16>c;c++)b.push(a+c);return b}register_dsp_command([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()});register_dsp_command([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});register_dsp_command([16],1,function(){var a=audio_normalize(this.write_buffer.shift(),127.5,-1);this.dac_buffers[0].push(a);this.dac_buffers[1].push(a);this.bus.send("dac-enable")});
register_dsp_command([20,21],2,function(){this.dma_irq=SB_IRQ_8BIT;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});register_dsp_command([22],2);register_dsp_command([23],2);register_dsp_command([28],0,function(){this.dma_irq=SB_IRQ_8BIT;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=!1;this.dma_transfer_start()});
register_dsp_command([31],0);register_dsp_command([32],0,function(){this.read_buffer.clear();this.read_buffer.push(127)});register_dsp_command([36],2);register_dsp_command([44],0);register_dsp_command([48],0);register_dsp_command([49],0);register_dsp_command([52],0);register_dsp_command([53],0);register_dsp_command([54],0);register_dsp_command([55],0);register_dsp_command([56],0);register_dsp_command([64],1,function(){this.sampling_rate_change(1E6/(256-this.write_buffer.shift())/this.get_channel_count())});
register_dsp_command([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});register_dsp_command([72],2,function(){this.dma_transfer_size_set()});register_dsp_command([116],2);register_dsp_command([117],2);register_dsp_command([118],2);register_dsp_command([119],2);register_dsp_command([125],0);register_dsp_command([127],0);register_dsp_command([128],2);
register_dsp_command([144],0,function(){this.dma_irq=SB_IRQ_8BIT;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});register_dsp_command([145],0);register_dsp_command([152],0);register_dsp_command([153],0);register_dsp_command([160],0);register_dsp_command([168],0);
register_dsp_command(any_first_digit(176),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=SB_IRQ_16BIT;this.dma_channel=this.dma_channel_16bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!0;this.dma_transfer_size_set();this.dma_transfer_start()}});
register_dsp_command(any_first_digit(192),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=SB_IRQ_8BIT;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!1;this.dma_transfer_size_set();this.dma_transfer_start()}});register_dsp_command([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});
register_dsp_command([209],0,function(){this.dummy_speaker_enabled=!0});register_dsp_command([211],0,function(){this.dummy_speaker_enabled=!1});register_dsp_command([212],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});register_dsp_command([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});register_dsp_command([214],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});
register_dsp_command([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});register_dsp_command([217,218],0,function(){this.dma_autoinit=!1});register_dsp_command([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())});register_dsp_command([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);this.read_buffer.push(5)});register_dsp_command([226],1);
register_dsp_command([227],0,function(){this.read_buffer.clear();for(var a=0;a<DSP_COPYRIGHT.length;a++)this.read_buffer.push(DSP_COPYRIGHT.charCodeAt(a));this.read_buffer.push(0)});register_dsp_command([228],1,function(){this.test_register=this.write_buffer.shift()});register_dsp_command([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});register_dsp_command([242,243],0,function(){this.raise_irq()});var SB_F9=new Uint8Array(256);SB_F9[14]=255;SB_F9[15]=7;
SB_F9[55]=56;register_dsp_command([249],1,function(){var a=this.write_buffer.shift();dbg_log("dsp 0xf9: unknown function. input: "+a,LOG_SB16);this.read_buffer.clear();this.read_buffer.push(SB_F9[a])});SB16.prototype.mixer_read=function(a){var b=MIXER_READ_HANDLERS[a];b?b=b.call(this):(b=this.mixer_registers[a],dbg_log("unhandled mixer register read. addr:"+h(a)+" data:"+h(b),LOG_SB16));return b};
SB16.prototype.mixer_write=function(a,b){var c=MIXER_WRITE_HANDLERS[a];c?c.call(this,b):dbg_log("unhandled mixer register write. addr:"+h(a)+" data:"+h(b),LOG_SB16)};SB16.prototype.mixer_default_read=function(){dbg_log("mixer register read. addr:"+h(this.mixer_current_address),LOG_SB16);return this.mixer_registers[this.mixer_current_address]};
SB16.prototype.mixer_default_write=function(a){dbg_log("mixer register write. addr:"+h(this.mixer_current_address)+" data:"+h(a),LOG_SB16);this.mixer_registers[this.mixer_current_address]=a};
SB16.prototype.mixer_reset=function(){this.mixer_registers[4]=204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=0;this.mixer_registers[46]=0;this.mixer_registers[10]=0;this.mixer_registers[48]=192;this.mixer_registers[49]=192;this.mixer_registers[50]=192;this.mixer_registers[51]=192;this.mixer_registers[52]=192;this.mixer_registers[53]=192;this.mixer_registers[54]=0;this.mixer_registers[55]=0;this.mixer_registers[56]=0;this.mixer_registers[57]=0;this.mixer_registers[59]=
0;this.mixer_registers[60]=31;this.mixer_registers[61]=21;this.mixer_registers[62]=11;this.mixer_registers[63]=0;this.mixer_registers[64]=0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};
SB16.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)MIXER_REGISTER_IS_LEGACY[a]||this.mixer_write(a,this.mixer_registers[a])};function register_mixer_read(a,b){b||(b=SB16.prototype.mixer_default_read);MIXER_READ_HANDLERS[a]=b}function register_mixer_write(a,b){b||(b=SB16.prototype.mixer_default_write);MIXER_WRITE_HANDLERS[a]=b}
function register_mixer_legacy(a,b,c){MIXER_REGISTER_IS_LEGACY[a]=1;MIXER_READ_HANDLERS[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};MIXER_WRITE_HANDLERS[a]=function(d){this.mixer_registers[a]=d;var e=d<<4&240|this.mixer_registers[c]&15;this.mixer_write(b,d&240|this.mixer_registers[b]&15);this.mixer_write(c,e)}}
function register_mixer_volume(a,b,c){MIXER_READ_HANDLERS[a]=SB16.prototype.mixer_default_read;MIXER_WRITE_HANDLERS[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",[b,c,(d>>>2)-62])}}register_mixer_read(0,function(){this.mixer_reset();return 0});register_mixer_write(0);register_mixer_legacy(4,50,51);register_mixer_legacy(34,48,49);register_mixer_legacy(38,52,53);register_mixer_legacy(40,54,55);register_mixer_legacy(46,56,57);register_mixer_volume(48,MIXER_SRC_MASTER,MIXER_CHANNEL_LEFT);
register_mixer_volume(49,MIXER_SRC_MASTER,MIXER_CHANNEL_RIGHT);register_mixer_volume(50,MIXER_SRC_DAC,MIXER_CHANNEL_LEFT);register_mixer_volume(51,MIXER_SRC_DAC,MIXER_CHANNEL_RIGHT);register_mixer_read(59);register_mixer_write(59,function(a){this.mixer_registers[59]=a;this.bus.send("mixer-volume",[MIXER_SRC_PCSPEAKER,MIXER_CHANNEL_BOTH,6*(a>>>6)-18])});register_mixer_read(65);register_mixer_write(65,function(a){this.mixer_registers[65]=a;this.bus.send("mixer-gain-left",6*(a>>>6))});register_mixer_read(66);
register_mixer_write(66,function(a){this.mixer_registers[66]=a;this.bus.send("mixer-gain-right",6*(a>>>6))});register_mixer_read(68);register_mixer_write(68,function(a){this.mixer_registers[68]=a;a>>>=3;this.bus.send("mixer-treble-left",a-(16>a?14:16))});register_mixer_read(69);register_mixer_write(69,function(a){this.mixer_registers[69]=a;a>>>=3;this.bus.send("mixer-treble-right",a-(16>a?14:16))});register_mixer_read(70);
register_mixer_write(70,function(a){this.mixer_registers[70]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});register_mixer_read(71);register_mixer_write(71,function(a){this.mixer_registers[71]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});register_mixer_read(128,function(){switch(this.irq){case SB_IRQ2:return 1;case SB_IRQ5:return 2;case SB_IRQ7:return 4;case SB_IRQ10:return 8;default:return 0}});
register_mixer_write(128,function(a){a&1&&(this.irq=SB_IRQ2);a&2&&(this.irq=SB_IRQ5);a&4&&(this.irq=SB_IRQ7);a&8&&(this.irq=SB_IRQ10)});register_mixer_read(129,function(){var a=0;switch(this.dma_channel_8bit){case SB_DMA0:a|=1;break;case SB_DMA1:a|=2;break;case SB_DMA3:a|=8}switch(this.dma_channel_16bit){case SB_DMA5:a|=32;break;case SB_DMA6:a|=64;break;case SB_DMA7:a|=128}return a});
register_mixer_write(129,function(a){a&1&&(this.dma_channel_8bit=SB_DMA0);a&2&&(this.dma_channel_8bit=SB_DMA1);a&8&&(this.dma_channel_8bit=SB_DMA3);a&32&&(this.dma_channel_16bit=SB_DMA5);a&64&&(this.dma_channel_16bit=SB_DMA6);a&128&&(this.dma_channel_16bit=SB_DMA7)});register_mixer_read(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.irq_triggered[b];return a});SB16.prototype.fm_default_write=function(a,b,c){dbg_log("unhandled fm register write. addr:"+b+"|"+h(c)+" data:"+h(a),LOG_SB16)};
function register_fm_write(a,b){b||(b=SB16.prototype.fm_default_write);for(var c=0;c<a.length;c++)FM_HANDLERS[a[c]]=b}function between(a,b){for(var c=[];a<=b;a++)c.push(a);return c}var SB_FM_OPERATORS_BY_OFFSET=new Uint8Array(32);SB_FM_OPERATORS_BY_OFFSET[0]=0;SB_FM_OPERATORS_BY_OFFSET[1]=1;SB_FM_OPERATORS_BY_OFFSET[2]=2;SB_FM_OPERATORS_BY_OFFSET[3]=3;SB_FM_OPERATORS_BY_OFFSET[4]=4;SB_FM_OPERATORS_BY_OFFSET[5]=5;SB_FM_OPERATORS_BY_OFFSET[8]=6;SB_FM_OPERATORS_BY_OFFSET[9]=7;
SB_FM_OPERATORS_BY_OFFSET[10]=8;SB_FM_OPERATORS_BY_OFFSET[11]=9;SB_FM_OPERATORS_BY_OFFSET[12]=10;SB_FM_OPERATORS_BY_OFFSET[13]=11;SB_FM_OPERATORS_BY_OFFSET[16]=12;SB_FM_OPERATORS_BY_OFFSET[17]=13;SB_FM_OPERATORS_BY_OFFSET[18]=14;SB_FM_OPERATORS_BY_OFFSET[19]=15;SB_FM_OPERATORS_BY_OFFSET[20]=16;SB_FM_OPERATORS_BY_OFFSET[21]=17;function get_fm_operator(a,b){return 18*a+SB_FM_OPERATORS_BY_OFFSET[b]}register_fm_write([1],function(a,b,c){this.fm_waveform_select_enable[b]=a&1;this.fm_update_waveforms()});
register_fm_write([2]);register_fm_write([3]);register_fm_write([4],function(a,b,c){});register_fm_write([5],function(a,b,c){0===b&&this.fm_default_write(a,b,c)});register_fm_write([8],function(a,b,c){});register_fm_write(between(32,53),function(a,b,c){get_fm_operator(b,c-32)});register_fm_write(between(64,85),function(a,b,c){get_fm_operator(b,c-64)});register_fm_write(between(96,117),function(a,b,c){get_fm_operator(b,c-96)});
register_fm_write(between(128,149),function(a,b,c){get_fm_operator(b,c-128)});register_fm_write(between(160,168),function(a,b,c){});register_fm_write(between(176,184),function(a,b,c){});register_fm_write([189],function(a,b,c){});register_fm_write(between(192,200),function(a,b,c){});register_fm_write(between(224,245),function(a,b,c){get_fm_operator(b,c-224)});SB16.prototype.fm_update_waveforms=function(){};
SB16.prototype.sampling_rate_change=function(a){this.sampling_rate=a;this.bus.send("dac-tell-sampling-rate",a)};SB16.prototype.get_channel_count=function(){return this.dsp_stereo?2:1};SB16.prototype.dma_transfer_size_set=function(){this.dma_sample_count=1+(this.write_buffer.shift()<<0)+(this.write_buffer.shift()<<8)};
SB16.prototype.dma_transfer_start=function(){dbg_log("begin dma transfer",LOG_SB16);this.bytes_per_sample=1;this.dsp_16bit&&(this.bytes_per_sample*=2);this.dma_bytes_count=this.dma_sample_count*this.bytes_per_sample;this.dma_bytes_block=SB_DMA_BLOCK_SAMPLES*this.bytes_per_sample;this.dma_bytes_block=Math.min(Math.max(this.dma_bytes_count>>2&-4,32),this.dma_bytes_block);this.dma_waiting_transfer=!0;this.dma.channel_mask[this.dma_channel]||this.dma_on_unmask(this.dma_channel)};
SB16.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))};
SB16.prototype.dma_transfer_next=function(){dbg_log("dma transfering next block",LOG_SB16);var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{dbg_log("dma block transfer "+(c?"unsuccessful":"successful"),LOG_SB16);c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||(this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})};
SB16.prototype.dma_to_dac=function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var g=0,f=0;f<a;f++)for(var k=audio_normalize(e[f],b,c),m=0;m<d;m++)this.dac_buffers[g].push(k),g^=1;this.dac_send()};SB16.prototype.dac_handle_request=function(){!this.dma_bytes_left||this.dma_paused?this.dac_send():this.dma_transfer_next()};
SB16.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};SB16.prototype.raise_irq=function(a){dbg_log("raise irq",LOG_SB16);this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};SB16.prototype.lower_irq=function(a){dbg_log("lower irq",LOG_SB16);this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};
function audio_normalize(a,b,c){return audio_clip(a/b+c,-1,1)}function audio_clip(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a};const VIRTIO_PCI_VENDOR_ID=6900,VIRTIO_PCI_CAP_VENDOR=9,VIRTIO_PCI_CAP_LENGTH=16,VIRTIO_PCI_CAP_COMMON_CFG=1,VIRTIO_PCI_CAP_NOTIFY_CFG=2,VIRTIO_PCI_CAP_ISR_CFG=3,VIRTIO_PCI_CAP_DEVICE_CFG=4,VIRTIO_PCI_CAP_PCI_CFG=5,VIRTIO_STATUS_ACKNOWLEDGE=1,VIRTIO_STATUS_DRIVER=2,VIRTIO_STATUS_DRIVER_OK=4,VIRTIO_STATUS_FEATURES_OK=8,VIRTIO_STATUS_DEVICE_NEEDS_RESET=64,VIRTIO_STATUS_FAILED=128,VIRTIO_ISR_QUEUE=1,VIRTIO_ISR_DEVICE_CFG=2,VIRTIO_F_RING_INDIRECT_DESC=28,VIRTIO_F_RING_EVENT_IDX=29,VIRTIO_F_VERSION_1=
32,VIRTQ_DESC_ENTRYSIZE=16,VIRTQ_AVAIL_BASESIZE=6,VIRTQ_AVAIL_ENTRYSIZE=2,VIRTQ_USED_BASESIZE=6,VIRTQ_USED_ENTRYSIZE=8,VIRTQ_IDX_MASK=65535,VIRTQ_DESC_F_NEXT=1,VIRTQ_DESC_F_WRITE=2,VIRTQ_DESC_F_INDIRECT=4,VIRTQ_AVAIL_F_NO_INTERRUPT=1,VIRTQ_USED_F_NO_NOTIFY=1;var VirtIO_CapabilityStruct,VirtIO_CapabilityInfo,VirtQueue_Options,VirtIO_CommonCapabilityOptions,VirtIO_NotificationCapabilityOptions,VirtIO_ISRCapabilityOptions,VirtIO_DeviceSpecificCapabilityOptions,VirtIO_Options;
function VirtIO(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=b.device_id;this.pci_space=[VIRTIO_PCI_VENDOR_ID&255,VIRTIO_PCI_VENDOR_ID>>8,b.device_id&255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,VIRTIO_PCI_VENDOR_ID&255,VIRTIO_PCI_VENDOR_ID>>8,b.subsystem_device_id&255,b.subsystem_device_id>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(v86util.zeros(256-this.pci_space.length));this.pci_id=b.pci_id;this.pci_bars=
[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)dbg_assert(0<=c,"VirtIO device<"+this.name+"> feature bit numbers must be non-negative"),dbg_assert(128>c,"VirtIO device<"+this.name+"> feature bit numbers assumed less than 128 in implementation"),this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);dbg_assert(b.common.features.includes(VIRTIO_F_VERSION_1),
"VirtIO device<"+this.name+"> only non-transitional devices are supported");this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(var d of b.common.queues)this.queues.push(new VirtQueue(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;if(DEBUG){c=new Set;for(var e of this.queues.map(g=>g.notify_offset))d=b.notification.single_handler?0:e,c.add(d),dbg_assert(b.notification.handlers[d],"VirtIO device<"+this.name+
"> every queue's notifier must exist");for(const [g,f]of b.notification.handlers.entries())dbg_assert(!f||c.has(g),"VirtIO device<"+this.name+"> no defined notify handler should be unused")}e=[];e.push(this.create_common_capability(b.common));e.push(this.create_notification_capability(b.notification));e.push(this.create_isr_capability(b.isr_status));b.device_specific&&e.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(e);a.devices.pci.register_device(this);this.reset()}
VirtIO.prototype.create_common_capability=function(a){return{type:VIRTIO_PCI_CAP_COMMON_CFG,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:b=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=
b}},{bytes:4,name:"driver_feature",read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>{dbg_log("No msi-x capability supported.",LOG_VIRTIO);return 65535},write:b=>{dbg_log("No msi-x capability supported.",LOG_VIRTIO)}},{bytes:2,name:"num_queues",
read:()=>this.queues.length,write:b=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b?(dbg_log("Reset device<"+this.name+">",LOG_VIRTIO),this.reset()):b&VIRTIO_STATUS_FAILED?dbg_log("Warning: Device<"+this.name+"> status failed",LOG_VIRTIO):dbg_log("Device<"+this.name+"> status: "+(b&VIRTIO_STATUS_ACKNOWLEDGE?"ACKNOWLEDGE ":"")+(b&VIRTIO_STATUS_DRIVER?"DRIVER ":"")+(b&VIRTIO_STATUS_DRIVER_OK?"DRIVER_OK":"")+(b&VIRTIO_STATUS_FEATURES_OK?"FEATURES_OK ":"")+(b&VIRTIO_STATUS_DEVICE_NEEDS_RESET?
"DEVICE_NEEDS_RESET":""),LOG_VIRTIO);b&~this.device_status&VIRTIO_STATUS_DRIVER_OK&&this.device_status&VIRTIO_STATUS_DEVICE_NEEDS_RESET&&this.notify_config_changes();this.features_ok||(DEBUG&&b&VIRTIO_STATUS_FEATURES_OK&&dbg_log("Removing FEATURES_OK",LOG_VIRTIO),b&=~VIRTIO_STATUS_FEATURES_OK);this.device_status=b;if(b&~this.device_status&VIRTIO_STATUS_DRIVER_OK)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:b=>{}},{bytes:2,name:"queue_select",read:()=>
this.queue_select,write:b=>{this.queue_select=b;this.queue_select<this.queues.length?this.queues_selected=this.queues[this.queue_select]:this.queue_selected=null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>{this.queue_selected&&(b&b-1&&(dbg_log("Warning: dev<"+this.name+"> Given queue size was not a power of 2. Rounding up to next power of 2.",LOG_VIRTIO),b=1<<v86util.int_log2(b-1)+1),b>this.queue_selected.size_supported&&(dbg_log("Warning: dev<"+
this.name+"> Trying to set queue size greater than supported. Clamping to supported size.",LOG_VIRTIO),b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>{dbg_log("No msi-x capability supported.",LOG_VIRTIO);return 65535},write:b=>{dbg_log("No msi-x capability supported.",LOG_VIRTIO)}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&(1===b?this.queue_selected.is_configured()?
this.queue_selected.enable():dbg_log("Driver bug: tried enabling unconfigured queue",LOG_VIRTIO):0===b&&dbg_log("Driver bug: tried writing 0 to queue_enable",LOG_VIRTIO))}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:0,write:b=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,
write:b=>{dbg_log("Warning: High dword of 64 bit queue_desc ignored",LOG_VIRTIO)}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:b=>{dbg_log("Warning: High dword of 64 bit queue_avail ignored",LOG_VIRTIO)}},{bytes:4,name:"queue_used (low dword)",read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&
(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:b=>{dbg_log("Warning: High dword of 64 bit queue_used ignored",LOG_VIRTIO)}}]}};
VirtIO.prototype.create_notification_capability=function(a){const b=[];let c;a.single_handler?(dbg_assert(1===a.handlers.length,"VirtIO device<"+this.name+"> too many notify handlers specified: expected single handler"),c=0):c=2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(g=>{})});return{type:VIRTIO_PCI_CAP_NOTIFY_CFG,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}};
VirtIO.prototype.create_isr_capability=function(a){return{type:VIRTIO_PCI_CAP_ISR_CFG,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:b=>{}}]}};
VirtIO.prototype.create_device_specific_capability=function(a){dbg_assert(~a.offset&3,"VirtIO device<"+this.name+"> device specific cap offset must be 4-byte aligned");return{type:VIRTIO_PCI_CAP_DEVICE_CFG,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};
VirtIO.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;var c=b;for(const e of a){a=VIRTIO_PCI_CAP_LENGTH+e.extra.length;c=b;b=c+a;dbg_assert(256>=b,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");dbg_assert(0<=e.bar&&6>e.bar,"VirtIO device<"+this.name+"> capability invalid bar number");var d=e.struct.reduce((g,f)=>g+f.bytes,0);d+=e.offset;d=16>d?16:1<<v86util.int_log2(d-1)+1;dbg_assert(0===(e.port&d-1),"VirtIO device<"+this.name+"> capability port should be aligned to pci bar size");
this.pci_bars[e.bar]={size:d};this.pci_space[c]=VIRTIO_PCI_CAP_VENDOR;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [g,
f]of e.extra.entries())this.pci_space[c+16+g]=f;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const g of e.struct){let f=g.read;a=g.write;DEBUG&&(f=()=>{const k=g.read();dbg_log("Device<"+this.name+"> cap["+e.type+"] read["+g.name+"] => "+h(k,8*g.bytes),LOG_VIRTIO);return k},a=k=>{dbg_log("Device<"+this.name+"> cap["+e.type+"] write["+g.name+"] <= "+h(k,8*g.bytes),
LOG_VIRTIO);g.write(k)});if(e.use_mmio)dbg_assert(!1,"VirtIO device <"+this.name+"> mmio capability not implemented.");else{d=function(m){dbg_log("Warning: 8-bit read from 16-bit virtio port",LOG_VIRTIO);return f(m&-2)>>((m&1)<<3)&255};const k=function(m){dbg_log("Warning: 8-bit read from 32-bit virtio port",LOG_VIRTIO);return f(m&-4)>>((m&3)<<3)&255};switch(g.bytes){case 4:this.cpu.io.register_read(c,this,k,void 0,f);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,
this,d,f);this.cpu.io.register_write(c,this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,f);this.cpu.io.register_write(c,this,a);break;default:dbg_assert(!1,"VirtIO device <"+this.name+"> invalid capability field width of "+g.bytes+" bytes")}}c+=g.bytes}}c=VIRTIO_PCI_CAP_LENGTH+4;dbg_assert(256>=b+c,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");this.pci_space[b]=VIRTIO_PCI_CAP_VENDOR;this.pci_space[b+1]=0;this.pci_space[b+2]=c;this.pci_space[b+3]=VIRTIO_PCI_CAP_PCI_CFG;
this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+18]=0;this.pci_space[b+19]=0};
VirtIO.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};
VirtIO.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(let c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};
VirtIO.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};
VirtIO.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&VIRTIO_STATUS_DRIVER_OK?this.raise_irq(VIRTIO_ISR_DEVICE_CFG):dbg_assert(!1,"VirtIO device<"+this.name+"> attempted to notify driver before DRIVER_OK")};VirtIO.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};
VirtIO.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};VirtIO.prototype.needs_reset=function(){dbg_log("Device<"+this.name+"> experienced error - requires reset",LOG_VIRTIO);this.device_status|=VIRTIO_STATUS_DEVICE_NEEDS_RESET;this.device_status&VIRTIO_STATUS_DRIVER_OK&&this.notify_config_changes()};VirtIO.prototype.raise_irq=function(a){dbg_log("Raise irq "+h(a),LOG_VIRTIO);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};
VirtIO.prototype.lower_irq=function(){dbg_log("Lower irq ",LOG_VIRTIO);this.isr_status=0;this.pci.lower_irq(this.pci_id)};function VirtQueue(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}
VirtQueue.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;return a};
VirtQueue.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};VirtQueue.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)};
VirtQueue.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};VirtQueue.prototype.enable=function(){dbg_assert(this.is_configured(),"VirtQueue must be configured before enabled");this.enabled=!0};VirtQueue.prototype.set_size=function(a){dbg_assert(0===(a&a-1),"VirtQueue size must be power of 2 or zero");dbg_assert(a<=this.size_supported,"VirtQueue size must be within supported size");this.size=a;this.mask=a-1};
VirtQueue.prototype.count_requests=function(){dbg_assert(this.avail_addr,"VirtQueue addresses must be configured before use");return this.avail_get_idx()-this.avail_last_idx&this.mask};VirtQueue.prototype.has_request=function(){dbg_assert(this.avail_addr,"VirtQueue addresses must be configured before use");return(this.avail_get_idx()&this.mask)!==this.avail_last_idx};
VirtQueue.prototype.pop_request=function(){dbg_assert(this.avail_addr,"VirtQueue addresses must be configured before use");dbg_assert(this.has_request(),"VirtQueue must not pop nonexistent request");var a=this.avail_get_entry(this.avail_last_idx);dbg_log("Pop request: avail_last_idx="+this.avail_last_idx+" desc_idx="+a,LOG_VIRTIO);a=new VirtQueueBufferChain(this,a);this.avail_last_idx=this.avail_last_idx+1&this.mask;return a};
VirtQueue.prototype.push_reply=function(a){dbg_assert(this.used_addr,"VirtQueue addresses must be configured before use");dbg_assert(this.num_staged_replies<this.size,"VirtQueue replies must not exceed queue size");const b=this.used_get_idx()+this.num_staged_replies&this.mask;dbg_log("Push reply: used_idx="+b+" desc_idx="+a.head_idx,LOG_VIRTIO);this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};
VirtQueue.prototype.flush_replies=function(){dbg_assert(this.used_addr,"VirtQueue addresses must be configured before use");if(0===this.num_staged_replies)dbg_log("flush_replies: Nothing to flush",LOG_VIRTIO);else{dbg_log("Flushing "+this.num_staged_replies+" replies",LOG_VIRTIO);var a=this.used_get_idx()+this.num_staged_replies&VIRTQ_IDX_MASK;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(VIRTIO_F_RING_EVENT_IDX)?(this.avail_get_used_event(),this.virtio.raise_irq(VIRTIO_ISR_QUEUE)):
~this.avail_get_flags()&VIRTQ_AVAIL_F_NO_INTERRUPT&&this.virtio.raise_irq(VIRTIO_ISR_QUEUE)}};VirtQueue.prototype.notify_me_after=function(a){dbg_assert(0<=a,"Must skip a non-negative number of requests");a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};
VirtQueue.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+b*VIRTQ_DESC_ENTRYSIZE),addr_high:this.cpu.read32s(a+b*VIRTQ_DESC_ENTRYSIZE+4),len:this.cpu.read32s(a+b*VIRTQ_DESC_ENTRYSIZE+8),flags:this.cpu.read16(a+b*VIRTQ_DESC_ENTRYSIZE+12),next:this.cpu.read16(a+b*VIRTQ_DESC_ENTRYSIZE+14)}};VirtQueue.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};VirtQueue.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};
VirtQueue.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+VIRTQ_AVAIL_ENTRYSIZE*a)};VirtQueue.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+VIRTQ_AVAIL_ENTRYSIZE*this.size)};VirtQueue.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};VirtQueue.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};VirtQueue.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};
VirtQueue.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};VirtQueue.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+VIRTQ_USED_ENTRYSIZE*a,b);this.cpu.write32(this.used_addr+8+VIRTQ_USED_ENTRYSIZE*a,c)};VirtQueue.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+VIRTQ_USED_ENTRYSIZE*this.size,a)};
function VirtQueueBufferChain(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,g=!1;const f=this.virtio.is_feature_negotiated(VIRTIO_F_RING_INDIRECT_DESC);dbg_log("<<< Descriptor chain start",LOG_VIRTIO);do{const k=a.get_descriptor(c,b);dbg_log("descriptor: idx="+
b+" addr="+h(k.addr_high,8)+":"+h(k.addr_low,8)+" len="+h(k.len,8)+" flags="+h(k.flags,4)+" next="+h(k.next,4),LOG_VIRTIO);if(f&&k.flags&VIRTQ_DESC_F_INDIRECT)DEBUG&&k.flags&VIRTQ_DESC_F_NEXT&&dbg_log("Driver bug: has set VIRTQ_DESC_F_NEXT flag in an indirect table descriptor",LOG_VIRTIO),c=k.addr_low,d=b=0,e=k.len/VIRTQ_DESC_ENTRYSIZE,dbg_log("start indirect",LOG_VIRTIO);else{if(k.flags&VIRTQ_DESC_F_WRITE)g=!0,this.write_buffers.push(k),this.length_writable+=k.len;else{if(g){dbg_log("Driver bug: readonly buffer after writeonly buffer within chain",
LOG_VIRTIO);break}this.read_buffers.push(k);this.length_readable+=k.len}d++;if(d>e){dbg_log("Driver bug: descriptor chain cycle detected",LOG_VIRTIO);break}if(k.flags&VIRTQ_DESC_F_NEXT)b=k.next;else break}}while(1);dbg_log("Descriptor chain end >>>",LOG_VIRTIO)}
VirtQueueBufferChain.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.read_buffer_idx===this.read_buffers.length){dbg_log("Device<"+this.virtio.name+"> Read more than device-readable buffers has",LOG_VIRTIO);break}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};
VirtQueueBufferChain.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.write_buffer_idx===this.write_buffers.length){dbg_log("Device<"+this.virtio.name+"> Write more than device-writable capacity",LOG_VIRTIO);break}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};var Bus={};function BusConnector(){this.listeners={};this.pair=void 0}BusConnector.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};BusConnector.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};
BusConnector.prototype.send=function(a,b,c){if(this.pair&&(a=this.pair.listeners[a],void 0!==a))for(c=0;c<a.length;c++){var d=a[c];d.fn.call(d.this_value,b)}};BusConnector.prototype.send_async=function(a,b){dbg_assert(1===arguments.length||2===arguments.length);setTimeout(this.send.bind(this,a,b),0)};Bus.create=function(){var a=new BusConnector,b=new BusConnector;a.pair=b;b.pair=a;return[a,b]};var log_data=[];function do_the_log(a){LOG_TO_FILE?log_data.push(a,"\n"):console.log(a)}
var dbg_log=function(){if(!DEBUG)return function(){};var a=LOG_NAMES.reduce(function(d,e){d[e[0]]=e[1];return d},{}),b="",c=0;return function(d,e){if(DEBUG&&(e=e||1,e&LOG_LEVEL)){d="["+v86util.pads(a[e]||"",4)+"] "+d;if(d===b&&(c++,2048>c))return;e=new Date;e=v86util.pad0(e.getHours(),2)+":"+v86util.pad0(e.getMinutes(),2)+":"+v86util.pad0(e.getSeconds(),2)+"+"+v86util.pad0(e.getMilliseconds(),3)+" ";c&&(1===c?do_the_log(e+b):do_the_log("Previous message repeated "+c+" times"),c=0);do_the_log(e+d);
b=d}}}();function dbg_trace(a){DEBUG&&dbg_log(Error().stack,a)}function dbg_assert(a,b,c){DEBUG&&(a||dbg_assert_failed(b))}function dbg_assert_failed(a){debugger;console.trace();if(a)throw"Assert failed: "+a;throw"Assert failed";};var CPU_LOG_VERBOSE=!1;
function CPU(a,b,c){this.next_tick_immediately=c;this.wm=b;this.wasm_patch();this.create_jit_imports();this.wasm_memory=b=this.wm.exports.memory;this.memory_size=v86util.view(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);this.segment_is_null=v86util.view(Uint8Array,b,724,8);this.segment_offsets=v86util.view(Int32Array,b,736,8);this.segment_limits=v86util.view(Uint32Array,b,768,8);this.protected_mode=v86util.view(Int32Array,b,800,1);this.idtr_size=v86util.view(Int32Array,
b,564,1);this.idtr_offset=v86util.view(Int32Array,b,568,1);this.gdtr_size=v86util.view(Int32Array,b,572,1);this.gdtr_offset=v86util.view(Int32Array,b,576,1);this.tss_size_32=v86util.view(Int32Array,b,1128,1);this.page_fault=v86util.view(Uint32Array,b,540,8);this.cr=v86util.view(Int32Array,b,580,8);this.cpl=v86util.view(Uint8Array,b,612,1);this.is_32=v86util.view(Int32Array,b,804,1);this.stack_size_32=v86util.view(Int32Array,b,808,1);this.in_hlt=v86util.view(Uint8Array,b,616,1);this.last_virt_eip=
v86util.view(Int32Array,b,620,1);this.eip_phys=v86util.view(Int32Array,b,624,1);this.sysenter_cs=v86util.view(Int32Array,b,636,1);this.sysenter_esp=v86util.view(Int32Array,b,640,1);this.sysenter_eip=v86util.view(Int32Array,b,644,1);this.prefixes=v86util.view(Int32Array,b,648,1);this.flags=v86util.view(Int32Array,b,120,1);this.flags_changed=v86util.view(Int32Array,b,116,1);this.last_op1=v86util.view(Int32Array,b,96,1);this.last_op_size=v86util.view(Int32Array,b,104,1);this.last_result=v86util.view(Int32Array,
b,112,1);this.current_tsc=v86util.view(Uint32Array,b,960,2);this.devices={};this.instruction_pointer=v86util.view(Int32Array,b,556,1);this.previous_ip=v86util.view(Int32Array,b,560,1);this.apic_enabled=v86util.view(Uint8Array,b,548,1);this.acpi_enabled=v86util.view(Uint8Array,b,552,1);this.memory_map_read8=[];this.memory_map_write8=[];this.memory_map_read32=[];this.memory_map_write32=[];this.bios={main:null,vga:null};this.instruction_counter=v86util.view(Uint32Array,b,664,1);this.reg32=v86util.view(Int32Array,
b,64,8);this.fpu_st=v86util.view(Int32Array,b,1152,32);this.fpu_stack_empty=v86util.view(Uint8Array,b,816,1);this.fpu_stack_empty[0]=255;this.fpu_stack_ptr=v86util.view(Uint8Array,b,1032,1);this.fpu_stack_ptr[0]=0;this.fpu_control_word=v86util.view(Uint16Array,b,1036,1);this.fpu_control_word[0]=895;this.fpu_status_word=v86util.view(Uint16Array,b,1040,1);this.fpu_status_word[0]=0;this.fpu_ip=v86util.view(Int32Array,b,1048,1);this.fpu_ip[0]=0;this.fpu_ip_selector=v86util.view(Int32Array,b,1052,1);this.fpu_ip_selector[0]=
0;this.fpu_opcode=v86util.view(Int32Array,b,1044,1);this.fpu_opcode[0]=0;this.fpu_dp=v86util.view(Int32Array,b,1056,1);this.fpu_dp[0]=0;this.fpu_dp_selector=v86util.view(Int32Array,b,1060,1);this.fpu_dp_selector[0]=0;this.reg_xmm32s=v86util.view(Int32Array,b,832,32);this.mxcsr=v86util.view(Int32Array,b,824,1);this.sreg=v86util.view(Uint16Array,b,668,8);this.dreg=v86util.view(Int32Array,b,684,8);this.reg_pdpte=v86util.view(Int32Array,b,968,8);this.svga_dirty_bitmap_min_offset=v86util.view(Uint32Array,
b,716,1);this.svga_dirty_bitmap_max_offset=v86util.view(Uint32Array,b,720,1);this.fw_value=[];this.fw_pointer=0;this.option_roms=[];this.io=void 0;this.bus=a;this.set_tsc(0,0);this.debug_init();DEBUG&&(this.do_many_cycles_total=this.do_many_cycles_count=0,this.seen_code={},this.seen_code_uncompiled={})}CPU.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};
CPU.prototype.create_jit_imports=function(){const a=Object.create(null);a.m=this.wm.exports.memory;for(let b of Object.keys(this.wm.exports))b.startsWith("_")||b.startsWith("zstd")||b.endsWith("_js")||(a[b]=this.wm.exports[b]);this.jit_imports=a};
CPU.prototype.wasm_patch=function(){const a=c=>this.wm.exports[c],b=c=>{const d=a(c);console.assert(d,"Missing import: "+c);return d};this.reset_cpu=b("reset_cpu");this.getiopl=b("getiopl");this.get_eflags=b("get_eflags");this.get_eflags_no_arith=b("get_eflags_no_arith");this.pic_call_irq=b("pic_call_irq");this.do_many_cycles_native=b("do_many_cycles_native");this.cycle_internal=b("cycle_internal");this.read8=b("read8");this.read16=b("read16");this.read32s=b("read32s");this.write8=b("write8");this.write16=
b("write16");this.write32=b("write32");this.in_mapped_range=b("in_mapped_range");this.fpu_load_tag_word=b("fpu_load_tag_word");this.fpu_load_status_word=b("fpu_load_status_word");this.fpu_get_sti_f64=b("fpu_get_sti_f64");this.translate_address_system_read=b("translate_address_system_read_js");this.get_seg_cs=b("get_seg_cs");this.get_real_eip=b("get_real_eip");this.clear_tlb=b("clear_tlb");this.full_clear_tlb=b("full_clear_tlb");this.set_tsc=b("set_tsc");this.store_current_tsc=b("store_current_tsc");
this.set_cpuid_level=b("set_cpuid_level");DEBUG&&(this.jit_force_generate_unsafe=a("jit_force_generate_unsafe"));this.jit_clear_cache=b("jit_clear_cache_js");this.jit_dirty_cache=b("jit_dirty_cache");this.codegen_finalize_finished=b("codegen_finalize_finished");this.allocate_memory=b("allocate_memory");this.zero_memory=b("zero_memory");this.svga_allocate_memory=b("svga_allocate_memory");this.svga_allocate_dest_buffer=b("svga_allocate_dest_buffer");this.svga_fill_pixel_buffer=b("svga_fill_pixel_buffer");
this.svga_mark_dirty=b("svga_mark_dirty");this.zstd_create_ctx=b("zstd_create_ctx");this.zstd_get_src_ptr=b("zstd_get_src_ptr");this.zstd_free_ctx=b("zstd_free_ctx");this.zstd_read=b("zstd_read");this.zstd_read_free=b("zstd_read_free")};CPU.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe?this.jit_force_generate_unsafe(a):dbg_assert(!1,"Not supported in this wasm build: jit_force_generate_unsafe")};
CPU.prototype.jit_clear_func=function(a){dbg_assert(0<=a&&a<WASM_TABLE_SIZE);this.wm.wasm_table.set(a+WASM_TABLE_OFFSET,null)};CPU.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;b<WASM_TABLE_SIZE;b++)a.set(WASM_TABLE_OFFSET+b,null)};
CPU.prototype.get_state=function(){var a=[];a[0]=this.memory_size[0];a[1]=this.segment_is_null;a[2]=this.segment_offsets;a[3]=this.segment_limits;a[4]=this.protected_mode[0];a[5]=this.idtr_offset[0];a[6]=this.idtr_size[0];a[7]=this.gdtr_offset[0];a[8]=this.gdtr_size[0];a[9]=this.page_fault[0];a[10]=this.cr;a[11]=this.cpl[0];a[13]=this.is_32[0];a[16]=this.stack_size_32[0];a[17]=this.in_hlt[0];a[18]=this.last_virt_eip[0];a[19]=this.eip_phys[0];a[22]=this.sysenter_cs[0];a[23]=this.sysenter_eip[0];a[24]=
this.sysenter_esp[0];a[25]=this.prefixes[0];a[26]=this.flags[0];a[27]=this.flags_changed[0];a[28]=this.last_op1[0];a[30]=this.last_op_size[0];a[37]=this.instruction_pointer[0];a[38]=this.previous_ip[0];a[39]=this.reg32;a[40]=this.sreg;a[41]=this.dreg;a[42]=this.reg_pdpte;this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.devices.apic;a[47]=this.devices.rtc;a[48]=this.devices.pci;a[49]=this.devices.dma;a[50]=this.devices.acpi;a[51]=this.devices.hpet;a[52]=this.devices.vga;
a[53]=this.devices.ps2;a[54]=this.devices.uart0;a[55]=this.devices.fdc;a[56]=this.devices.cdrom;a[57]=this.devices.hda;a[58]=this.devices.pit;a[59]=this.devices.net;a[60]=this.devices.pic;a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.devices.ioapic;a[64]=this.tss_size_32[0];a[66]=this.reg_xmm32s;a[67]=this.fpu_st;a[68]=this.fpu_stack_empty[0];a[69]=this.fpu_stack_ptr[0];a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0];a[74]=this.fpu_dp_selector[0];
a[75]=this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;return a};
CPU.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]);this.segment_is_null.set(a[1]);this.segment_offsets.set(a[2]);this.segment_limits.set(a[3]);this.protected_mode[0]=a[4];this.idtr_offset[0]=a[5];this.idtr_size[0]=a[6];this.gdtr_offset[0]=a[7];this.gdtr_size[0]=a[8];this.page_fault[0]=a[9];this.cr.set(a[10]);this.cpl[0]=a[11];this.is_32[0]=a[13];this.stack_size_32[0]=
a[16];this.in_hlt[0]=a[17];this.last_virt_eip[0]=a[18];this.eip_phys[0]=a[19];this.sysenter_cs[0]=a[22];this.sysenter_eip[0]=a[23];this.sysenter_esp[0]=a[24];this.prefixes[0]=a[25];this.flags[0]=a[26];this.flags_changed[0]=a[27];this.last_op1[0]=a[28];this.last_op_size[0]=a[30];this.instruction_pointer[0]=a[37];this.previous_ip[0]=a[38];this.reg32.set(a[39]);this.sreg.set(a[40]);this.dreg.set(a[41]);a[42]&&this.reg_pdpte.set(a[42]);this.set_tsc(a[43][0],a[43][1]);this.devices.virtio_9p&&this.devices.virtio_9p.set_state(a[45]);
this.devices.apic&&this.devices.apic.set_state(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.pci&&this.devices.pci.set_state(a[48]);this.devices.dma&&this.devices.dma.set_state(a[49]);this.devices.acpi&&this.devices.acpi.set_state(a[50]);this.devices.hpet&&this.devices.hpet.set_state(a[51]);this.devices.vga&&this.devices.vga.set_state(a[52]);this.devices.ps2&&this.devices.ps2.set_state(a[53]);this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);
this.devices.cdrom&&this.devices.cdrom.set_state(a[56]);this.devices.hda&&this.devices.hda.set_state(a[57]);this.devices.pit&&this.devices.pit.set_state(a[58]);this.devices.net&&this.devices.net.set_state(a[59]);this.devices.pic&&this.devices.pic.set_state(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.fw_value=a[62];
this.devices.ioapic&&this.devices.ioapic.set_state(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];const b=new v86util.Bitmap(a[78].buffer);this.unpack_memory(b,a[77]);this.full_clear_tlb();this.jit_clear_cache()};
CPU.prototype.pack_memory=function(){dbg_assert(0===(this.mem8.length&4095));var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++){var d=c<<12;d=this.mem32s.subarray(d>>2,d+4096>>2);let e=!0;for(let g=0;g<d.length;g++)if(0!==d[g]){e=!1;break}e||b.push(c)}a=new v86util.Bitmap(a);c=new Uint8Array(b.length<<12);for(let [e,g]of b.entries())a.set(g,1),b=g<<12,b=this.mem8.subarray(b,b+4096),c.set(b,e<<12);return{bitmap:a,packed_memory:c}};
CPU.prototype.unpack_memory=function(a,b){this.zero_memory(this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let g=0;g<c;g++)if(a.get(g)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,g<<12);d++}};CPU.prototype.main_run=function(){if(this.in_hlt[0]){var a=this.hlt_loop();if(this.in_hlt[0])return a}let b=a=v86.microtick();for(;b-a<TIME_PER_FRAME;){this.do_many_cycles();b=v86.microtick();const c=this.run_hardware_timers(b);this.handle_irqs();if(this.in_hlt[0])return c}return 0};
CPU.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio&&this.devices.virtio.reset();this.load_bios()};CPU.prototype.reset_memory=function(){this.mem8.fill(0)};
CPU.prototype.create_memory=function(a){1048576>a?a=1048576:0>(a|0)&&(a=Math.pow(2,31)-MMAP_BLOCK_SIZE);a=(a-1|MMAP_BLOCK_SIZE-1)+1|0;dbg_assert(0<(a|0));dbg_assert(0===(a&MMAP_BLOCK_SIZE-1));console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;const b=this.allocate_memory(a);this.mem8=v86util.view(Uint8Array,this.wasm_memory,b,a);this.mem32s=v86util.view(Uint32Array,this.wasm_memory,b,a>>2)};goog.exportProperty(CPU.prototype,"create_memory",CPU.prototype.create_memory);
CPU.prototype.init=function(a,b){"number"===typeof a.log_level&&(LOG_LEVEL=a.log_level);this.create_memory("number"===typeof a.memory_size?a.memory_size:67108864);a.cpuid_level&&this.set_cpuid_level(a.cpuid_level);this.acpi_enabled[0]=+a.acpi;this.reset_cpu();var c=new IO(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const {option_rom:e}=load_kernel(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){dbg_log("port 0xB3 read");
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(){if(this.fw_pointer<this.fw_value.length)return this.fw_value[this.fw_pointer++];dbg_assert(!1,"config port: Read past value");return 0});c.register_write(1296,this,void 0,function(e){function g(m){return new Uint8Array((new Int32Array([m])).buffer)}function f(m){return m>>8|m<<8&65280}function k(m){return m<<24|m<<8&16711680|m>>8&65280|m>>>24}dbg_log("bios config port, index="+
h(e));this.fw_pointer=0;if(e===FW_CFG_SIGNATURE)this.fw_value=g(FW_CFG_SIGNATURE_QEMU);else if(e===FW_CFG_ID)this.fw_value=g(0);else if(e===FW_CFG_RAM_SIZE)this.fw_value=g(this.memory_size[0]);else if(e===FW_CFG_NB_CPUS)this.fw_value=g(1);else if(e===FW_CFG_MAX_CPUS)this.fw_value=g(1);else if(e===FW_CFG_NUMA)this.fw_value=new Uint8Array(16);else if(e===FW_CFG_FILE_DIR){e=new Int32Array(4+64*this.option_roms.length);const m=new Uint8Array(e.buffer);e[0]=k(this.option_roms.length);for(let l=0;l<this.option_roms.length;l++){const {name:n,
data:p}=this.option_roms[l],t=4+64*l;dbg_assert(65536>FW_CFG_FILE_START+l);e[t+0>>2]=k(p.length);e[t+4>>2]=f(FW_CFG_FILE_START+l);dbg_assert(56>n.length);for(let r=0;r<n.length;r++)m[t+8+r]=n.charCodeAt(r)}this.fw_value=m}else e>=FW_CFG_CUSTOM_START&&e<FW_CFG_FILE_START?this.fw_value=g(0):e>=FW_CFG_FILE_START&&e-FW_CFG_FILE_START<this.option_roms.length?this.fw_value=this.option_roms[e-FW_CFG_FILE_START].data:(dbg_log("Warning: Unimplemented fw index: "+h(e)),this.fw_value=g(0))});DEBUG&&(c.register_write(128,
this,function(e){}),c.register_read(128,this,function(){return 255}),c.register_write(233,this,function(e){}));this.devices={};a.load_devices&&(this.devices.pic=new PIC(this),this.devices.pci=new PCI(this),this.acpi_enabled[0]&&(this.devices.ioapic=new IOAPIC(this),this.devices.apic=new APIC(this),this.devices.acpi=new ACPI(this)),this.devices.rtc=new RTC(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new DMA(this),ENABLE_HPET&&(this.devices.hpet=new HPET(this)),this.devices.vga=new VGAScreen(this,
b,a.vga_memory_size||8388608),this.devices.ps2=new PS2(this,b),this.devices.uart0=new UART(this,1016,b),a.uart1&&(this.devices.uart1=new UART(this,760,b)),a.uart2&&(this.devices.uart2=new UART(this,1E3,b)),a.uart3&&(this.devices.uart3=new UART(this,744,b)),this.devices.fdc=new FloppyController(this,a.fda,a.fdb),c=0,a.hda&&(this.devices.hda=new IDEDevice(this,a.hda,a.hdb,!1,c++,b)),a.cdrom&&(this.devices.cdrom=new IDEDevice(this,a.cdrom,void 0,!0,c++,b)),this.devices.pit=new PIT(this,b),a.enable_ne2k&&
(this.devices.net=new Ne2k(this,b,a.preserve_mac_from_state_image,a.mac_address_translation)),a.fs9p&&(this.devices.virtio_9p=new Virtio9p(a.fs9p,this,b)),this.devices.sb16=new SB16(this,b));a.multiboot&&this.load_multiboot(a.multiboot);DEBUG&&this.debug.init()};
CPU.prototype.load_multiboot=function(a){dbg_log("Trying multiboot from buffer of size "+a.byteLength,LOG_CPU);if(8192>a.byteLength){var b=new Int32Array(2048);(new Uint8Array(b.buffer)).set(new Uint8Array(a))}else b=new Int32Array(a,0,2048);for(var c=0;8192>c;c+=4)if(464367618===b[c>>2]){var d=b[c+4>>2];if(464367618+d+b[c+8>>2]|0)dbg_log("Multiboot checksum check failed",LOG_CPU);else{dbg_log("Multiboot magic found, flags: "+h(d>>>0,8),LOG_CPU);dbg_assert(0===(d&-65537),"TODO");this.reg32[REG_EAX]=
732803074;this.reg32[REG_EBX]=31744;this.write32(31744,0);this.cr[0]=1;this.protected_mode[0]=1;this.flags[0]=FLAGS_DEFAULT;this.is_32[0]=1;this.stack_size_32[0]=1;for(var e=0;6>e;e++)this.segment_is_null[e]=0,this.segment_offsets[e]=0,this.segment_limits[e]=4294967295,this.sreg[e]=45058;if(d&65536){dbg_log("Multiboot specifies its own address table",LOG_CPU);e=b[c+12>>2];var g=b[c+16>>2];d=b[c+20>>2];var f=b[c+24>>2];b=b[c+28>>2];dbg_log("header="+h(e,8)+" load="+h(g,8)+" load_end="+h(d,8)+" bss_end="+
h(f,8)+" entry="+h(b,8));dbg_assert(g<=e);c-=e-g;0===d?d=void 0:(dbg_assert(d>=g),d-=g);a=new Uint8Array(a,c,d);this.write_blob(a,g);this.instruction_pointer[0]=this.get_seg_cs()+b|0}else if(1179403647===b[0]){dbg_log("Multiboot image is in elf format",LOG_CPU);c=read_elf(a);this.instruction_pointer[0]=this.get_seg_cs()+c.header.entry|0;for(g of c.program_headers)0!==g.type&&(1===g.type?(dbg_assert(g.paddr===g.vaddr),dbg_assert(g.filesz<=g.memsz),g.paddr+g.memsz<this.memory_size[0]?g.filesz&&(c=new Uint8Array(a,
g.offset,g.filesz),this.write_blob(c,g.paddr)):dbg_log("Warning: Skipped loading section, paddr="+h(g.paddr)+" memsz="+g.memsz,LOG_CPU)):2!==g.type&&3!==g.type&&4!==g.type&&6!==g.type&&1685382480!==g.type&&1685382481!==g.type&&1685382483!==g.type&&dbg_assert(!1,"unimplemented elf section type: "+h(g.type)))}else dbg_assert(!1,"Not a bootable multiboot format");this.io.register_write_consecutive(244,this,function(k){console.log("Test exited with code "+h(k,2));throw"HALT";},function(){},function(){},
function(){});for(let k=14;15>=k;k++)this.io.register_write(8192+k,this,function(m){dbg_log("kvm-unit-test: Set irq "+h(k)+" to "+h(m,2));m?this.device_raise_irq(k):this.device_lower_irq(k)});dbg_log("Starting multiboot kernel at:",LOG_CPU);this.debug.dump_state();this.debug.dump_regs();break}}};
CPU.prototype.fill_cmos=function(a,b){var c=b.boot_order||531;a.cmos_write(CMOS_BIOS_BOOTFLAG1,1|c>>4&240);a.cmos_write(CMOS_BIOS_BOOTFLAG2,c&255);a.cmos_write(CMOS_MEM_BASE_LOW,128);a.cmos_write(CMOS_MEM_BASE_HIGH,2);c=0;1048576<=this.memory_size[0]&&(c=this.memory_size[0]-1048576>>10,c=Math.min(c,65535));a.cmos_write(CMOS_MEM_OLD_EXT_LOW,c&255);a.cmos_write(CMOS_MEM_OLD_EXT_HIGH,c>>8&255);a.cmos_write(CMOS_MEM_EXTMEM_LOW,c&255);a.cmos_write(CMOS_MEM_EXTMEM_HIGH,c>>8&255);c=0;16777216<=this.memory_size[0]&&
(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(CMOS_MEM_EXTMEM2_LOW,c&255);a.cmos_write(CMOS_MEM_EXTMEM2_HIGH,c>>8&255);a.cmos_write(CMOS_MEM_HIGHMEM_LOW,0);a.cmos_write(CMOS_MEM_HIGHMEM_MID,0);a.cmos_write(CMOS_MEM_HIGHMEM_HIGH,0);a.cmos_write(CMOS_EQUIPMENT_INFO,47);a.cmos_write(CMOS_BIOS_SMP_COUNT,0);b.fastboot&&a.cmos_write(63,1)};
CPU.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e<d.length?d[e]:0},function(e,g){dbg_assert(!1,"Unexpected write to VGA rom")})}else dbg_log("Warning: No VGA BIOS");this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,g){this.mem8[e&
1048575]=g}.bind(this))}else dbg_log("Warning: No BIOS")};CPU.prototype.do_many_cycles=function(){if(DEBUG)var a=v86.microtick();this.do_many_cycles_native();DEBUG&&(this.do_many_cycles_total+=v86.microtick()-a,this.do_many_cycles_count++)};CPU.prototype.cycle=function(){this.cycle_internal()};goog.exportProperty(CPU.prototype,"cycle",CPU.prototype.cycle);
CPU.prototype.codegen_finalize=function(a,b,c,d,e){d>>>=0;e>>>=0;dbg_assert(0<=a&&a<WASM_TABLE_SIZE);const g=new Uint8Array(this.wasm_memory.buffer,d,e);DEBUG&&(DUMP_GENERATED_WASM&&!this.seen_code[b]&&this.debug.dump_wasm(g),this.seen_code[b]=(this.seen_code[b]||0)+1,this.test_hook_did_generate_wasm&&this.test_hook_did_generate_wasm(g));d=WebAssembly.instantiate(g,{e:this.jit_imports}).then(f=>{f=f.instance.exports.f;this.codegen_finalize_finished(a,b,c);this.wm.wasm_table.set(a+WASM_TABLE_OFFSET,
f);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(g)});DEBUG&&d.catch(f=>{console.log(f);debugger;throw f;})};
CPU.prototype.log_uncompiled_code=function(a,b){if(DEBUG&&DUMP_UNCOMPILED_ASSEMBLY&&100>(this.seen_code_uncompiled[a]||0)){this.seen_code_uncompiled[a]=(this.seen_code_uncompiled[a]||0)+1;b+=8;(a^b)&-4096&&(dbg_log("truncated disassembly start="+h(a>>>0)+" end="+h(b>>>0)),b=(a|4095)+1);b<a&&(b=a);dbg_assert(b>=a);const c=new Uint8Array(b-a);for(let d=a;d<b;d++)c[d-a]=this.read8(d);dbg_log("Uncompiled code:");this.debug.dump_code(this.is_32[0]?1:0,c,a)}};
CPU.prototype.dump_function_code=function(a,b){if(DEBUG&&DUMP_GENERATED_WASM){var c=new Int32Array(this.wasm_memory.buffer);dbg_assert(0===(a&3));var d=this.is_32[0];for(let g=0;g<b;g++){var e=(a>>2)+7*g;const f=c[e+0],k=c[e+1];e=c[e+6]&65280;const m=new Uint8Array(k-f);for(let l=f;l<k;l++)m[l-f]=this.read8(this.translate_address_system_read(l));dbg_log("---"+(e?" entry":""));this.debug.dump_code(d?1:0,m,f)}}};
CPU.prototype.hlt_loop=function(){if(this.get_eflags_no_arith()&FLAG_INTERRUPT){const a=this.run_hardware_timers(v86.microtick());this.handle_irqs();return a}return 100};
CPU.prototype.run_hardware_timers=function(a){if(ENABLE_HPET)var b=this.devices.pit.timer(a,this.devices.hpet.legacy_mode),c=this.devices.rtc.timer(a,this.devices.hpet.legacy_mode),d=this.devices.hpet.timer(a);else b=this.devices.pit.timer(a,!1),c=this.devices.rtc.timer(a,!1),d=100;let e=100,g=100;this.acpi_enabled[0]&&(e=this.devices.acpi.timer(a),g=this.devices.apic.timer(a));return Math.min(b,c,d,e,g)};
CPU.prototype.hlt_op=function(){0===(this.get_eflags_no_arith()&FLAG_INTERRUPT)&&this.bus.send("cpu-event-halt");this.in_hlt[0]=1;this.hlt_loop()};CPU.prototype.handle_irqs=function(){this.get_eflags_no_arith()&FLAG_INTERRUPT&&(this.pic_acknowledge(),this.next_tick_immediately())};CPU.prototype.pic_acknowledge=function(){dbg_assert(this.get_eflags_no_arith()&FLAG_INTERRUPT);this.devices.pic&&this.devices.pic.acknowledge_irq();this.devices.apic&&this.devices.apic.acknowledge_irq()};
CPU.prototype.device_raise_irq=function(a){dbg_assert(1===arguments.length);this.devices.pic&&this.devices.pic.set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};CPU.prototype.device_lower_irq=function(a){this.devices.pic&&this.devices.pic.clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};"undefined"!==typeof window?window.CPU=CPU:"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.CPU=CPU:"function"===typeof importScripts&&(self.CPU=CPU);CPU.prototype.debug_init=function(){function a(l){if(DEBUG){for(var n=e.protected_mode[0]?"prot":"real",p=e.get_eflags(),t=e.getiopl(),r=e.cpl[0],q=h(e.sreg[REG_CS],4)+":"+h(e.get_real_eip()>>>0,8),v=h(e.sreg[REG_SS],4)+":"+h(e.reg32[REG_ES]>>>0,8),u=e.is_32[0]?"32":"16",x=e.flags[0]&FLAG_INTERRUPT?1:0,z={[FLAG_CARRY]:"c",[FLAG_PARITY]:"p",[FLAG_ADJUST]:"a",[FLAG_ZERO]:"z",[FLAG_SIGN]:"s",[FLAG_TRAP]:"t",[FLAG_INTERRUPT]:"i",[FLAG_DIRECTION]:"d",[FLAG_OVERFLOW]:"o"},C="",D=0;16>D;D++)z[1<<D]&&(C=
p&1<<D?C+z[1<<D]:C+" ");return"mode="+n+"/"+u+" paging="+ +(0!==(e.cr[0]&CR0_PG))+" pae="+ +(0!==(e.cr[4]&CR4_PAE))+" iopl="+t+" cpl="+r+" if="+x+" cs:eip="+q+" cs_off="+h(e.get_seg_cs()>>>0,8)+" flgs="+h(e.get_eflags()>>>0,6)+" ("+C+") ss:esp="+v+" ssize="+ +e.stack_size_32[0]+(l?" in "+l:"")}}function b(){if(DEBUG){for(var l={eax:REG_EAX,ecx:REG_ECX,edx:REG_EDX,ebx:REG_EBX,esp:REG_ESP,ebp:REG_EBP,esi:REG_ESI,edi:REG_EDI},n="eax ecx edx ebx esp ebp esi edi".split(" "),p="",t="",r=0;4>r;r++)p+=n[r]+
"="+h(e.reg32[l[n[r]]]>>>0,8)+" ",t+=n[r+4]+"="+h(e.reg32[l[n[r+4]]]>>>0,8)+" ";p+=" ds="+h(e.sreg[REG_DS],4)+" es="+h(e.sreg[REG_ES],4)+" fs="+h(e.sreg[REG_FS],4);t+=" gs="+h(e.sreg[REG_GS],4)+" cs="+h(e.sreg[REG_CS],4)+" ss="+h(e.sreg[REG_SS],4);return[p,t]}}function c(l,n,p){if(DEBUG){if(!(l&1))return!1;var t=128===(l&128);return{size:t,global:256===(l&256),accessed:32===(l&32),dirty:64===(l&64),cache_disable:16===(l&16),user:4===(l&4),read_write:2===(l&2),address:(t&&!p?l&(n?4292870144:4290772992):
l&4294963200)>>>0}}}function d(l,n,p){if(DEBUG)for(var t=n?512:1024,r=n?8:4,q=n?21:22,v=0;v<t;v++){var u=e.read32s(l+v*r),x=c(u,n,!0);if(x)if(u="",u+=x.size?"S ":" ",u+=x.accessed?"A ":" ",u+=x.cache_disable?"Cd ":" ",u+=x.user?"U ":" ",u+=x.read_write?"Rw ":" ",x.size)dbg_log("=== "+h(p+(v<<q)>>>0,8)+" -> "+h(x.address>>>0,8)+" | "+u);else{dbg_log("=== "+h(p+(v<<q)>>>0,8)+" | "+u);for(var z=0;z<t;z++){var C=x.address+z*r;u=e.read32s(C);var D=c(u,n,!1);D&&(u="",u+=D.cache_disable?"Cd ":" ",
u+=D.user?"U ":" ",u+=D.read_write?"Rw ":" ",u+=D.global?"G ":" ",u+=D.accessed?"A ":" ",u+=D.dirty?"Di ":" ",dbg_log("# "+h(p+(v<<q|z<<12)>>>0,8)+" -> "+h(D.address,8)+" | "+u+" (at "+h(C,8)+")"))}}}}var e=this,g={};this.debug=g;g.init=function(){function l(p){10===p?(dbg_log(n,LOG_BIOS),n=""):n+=String.fromCharCode(p)}if(DEBUG&&e.io){var n="";e.io.register_write(1026,this,l);e.io.register_write(1280,this,l)}};g.get_regs_short=b;g.dump_regs=function(){if(DEBUG){var l=b();dbg_log(l[0],
LOG_CPU);dbg_log(l[1],LOG_CPU)}};g.get_state=a;g.dump_state=function(l){DEBUG&&dbg_log(a(l),LOG_CPU)};g.dump_stack=function(l,n){if(DEBUG){var p=e.reg32[REG_ESP];dbg_log("========= STACK ==========");if(n>=l||void 0===n)l=5,n=-5;for(;l>n;l--){var t=" ";l||(t="=> ");t+=h(l,2)+" | ";dbg_log(t+h(p+4*l,8)+" | "+h(e.read32s(p+4*l)>>>0))}}};g.dump_page_structures=function(){if(e.cr[4]&CR4_PAE){dbg_log("PAE enabled");for(var l=0;4>l;l++){var n=e.read32s(e.cr[3]+8*l);n&1&&d(n&4294963200,!0,l<<30)}}else dbg_log("PAE disabled"),
d(e.cr[3],!1,0)};g.dump_gdt_ldt=function(){function l(n,p){for(var t=0;t<p;t+=8,n+=8){var r=e.read16(n+2)|e.read8(n+4)<<16|e.read8(n+7)<<24,q=e.read16(n)|(e.read8(n+6)&15)<<16,v=e.read8(n+5),u=e.read8(n+6)>>4,x="",z=v>>5&3;x=v&128?x+" P ":x+"NP ";v&16?(x=u&4?x+"32b ":x+"16b ",v&8?(x+="X ",v&4&&(x+="C ")):x+="R ",x+="RW "):x+="sys: "+h(v&15);u&8&&(q=q<<12|4095);dbg_log(h(t&-8,4)+" "+h(r>>>0,8)+" ("+h(q>>>0,8)+" bytes) "+x+"; dpl = "+z+", a = "+v.toString(2)+", f = "+u.toString(2))}}DEBUG&&(dbg_log("gdt: (len = "+
h(e.gdtr_size[0])+")"),l(e.translate_address_system_read(e.gdtr_offset[0]),e.gdtr_size[0]),dbg_log("\nldt: (len = "+h(e.segment_limits[REG_LDTR])+")"),l(e.translate_address_system_read(e.segment_offsets[REG_LDTR]),e.segment_limits[REG_LDTR]))};g.dump_idt=function(){if(DEBUG)for(var l=0;l<e.idtr_size[0];l+=8){var n=e.translate_address_system_read(e.idtr_offset[0]+l),p=e.read16(n)|e.read16(n+6)<<16,t=e.read16(n+2);n=e.read8(n+5);var r=n>>5&3;var q=5===(n&31)?"task gate ":14===(n&31)?"intr gate ":15===
(n&31)?"trap gate ":"invalid ";q=n&128?q+" P":q+"NP";dbg_log(h(l>>3,4)+" "+h(p>>>0,8)+", "+h(t,4)+"; "+q+"; dpl = "+r+", t = "+n.toString(2))}};g.get_memory_dump=function(l,n){if(DEBUG)return void 0===l?(l=0,n=e.memory_size[0]):void 0===n&&(n=l,l=0),e.mem8.slice(l,l+n).buffer};g.memory_hex_dump=function(l,n){if(DEBUG){n=n||64;for(var p,t,r=0;r<n>>4;r++){p=h(l+(r<<4),5)+" ";for(var q=0;16>q;q++)t=e.read8(l+(r<<4)+q),p+=h(t,2)+" ";p+=" ";for(q=0;16>q;q++)t=e.read8(l+(r<<4)+q),p+=33>t||126<t?".":
String.fromCharCode(t);dbg_log(p)}}};g.used_memory_dump=function(){if(DEBUG)for(var l=e.memory_size[0]/128/16|0,n,p=0;16>p;p++){n=h(128*p*l,8)+" | ";for(var t=0;128>t;t++)n+=0<e.mem32s[(128*p+t)*l]?"X":" ";dbg_log(n)}};g.debug_interrupt=function(l){};let f,k;g.dump_code=function(l,n,p){if(!k){if(void 0===f&&(f="function"===typeof require?require("./capstone-x86.min.js"):window.cs,void 0===f)){dbg_log("Warning: Missing capstone library, disassembly not available");return}k=[new f.Capstone(f.ARCH_X86,
f.MODE_16),new f.Capstone(f.ARCH_X86,f.MODE_32)]}try{k[l].disasm(n,p).forEach(function(t){dbg_log(h(t.address>>>0)+": "+v86util.pads(t.bytes.map(r=>h(r,2).slice(-2)).join(" "),20)+" "+t.mnemonic+" "+t.op_str)}),dbg_log("")}catch(t){dbg_log("Could not disassemble: "+Array.from(n).map(r=>h(r,2)).join(" "))}};let m;g.dump_wasm=function(l){if(void 0===m&&(m="function"===typeof require?require("./libwabt.js"):new window.WabtModule,void 0===m)){dbg_log("Warning: Missing libwabt, wasm dump not available");
return}l=l.slice();try{var n=m.readWasm(l,{readDebugNames:!1});n.generateNames();n.applyNames();const r=n.toText({foldExprs:!0,inlineExport:!0});dbg_log(r)}catch(r){var p=new Blob([l]),t=document.createElement("a");t.download="failed.wasm";t.href=window.URL.createObjectURL(p);t.dataset.downloadurl=["application/octet-stream",t.download,t.href].join(":");t.click();window.URL.revokeObjectURL(t.src);console.log(r.toString())}finally{n&&n.destroy()}}};const ELF_MAGIC=1179403647;
let types=DataView.prototype,U8={size:1,get:types.getUint8,set:types.setUint8},U16={size:2,get:types.getUint16,set:types.setUint16},U32={size:4,get:types.getUint32,set:types.setUint32},pad=function(a){return{size:a,get:b=>-1}},Header=create_struct([{magic:U32},{class:U8},{data:U8},{version0:U8},{osabi:U8},{abiversion:U8},{pad0:pad(7)},{type:U16},{machine:U16},{version1:U32},{entry:U32},{phoff:U32},{shoff:U32},{flags:U32},{ehsize:U16},{phentsize:U16},{phnum:U16},{shentsize:U16},{shnum:U16},{shstrndx:U16}]);
console.assert(52===Header.reduce((a,b)=>a+b.size,0));let ProgramHeader=create_struct([{type:U32},{offset:U32},{vaddr:U32},{paddr:U32},{filesz:U32},{memsz:U32},{flags:U32},{align:U32}]);console.assert(32===ProgramHeader.reduce((a,b)=>a+b.size,0));let SectionHeader=create_struct([{name:U32},{type:U32},{flags:U32},{addr:U32},{offset:U32},{size:U32},{link:U32},{info:U32},{addralign:U32},{entsize:U32}]);console.assert(40===SectionHeader.reduce((a,b)=>a+b.size,0));
function create_struct(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 read_elf(a){a=new DataView(a);let [b,c]=read_struct(a,Header);console.assert(52===c);if(DEBUG){for(var d of Object.keys(b))dbg_log(d+": 0x"+b[d].toString(16));dbg_log(b)}console.assert(b.magic===ELF_MAGIC,"Bad magic");console.assert(1===b.class,"Unimplemented: 64 bit elf");console.assert(1===b.data,"Unimplemented: big endian");console.assert(1===b.version0,"Bad version0");console.assert(2===b.type,"Unimplemented type");console.assert(1===b.version1,"Bad version1");console.assert(52===b.ehsize,
"Bad header size");console.assert(32===b.phentsize,"Bad program header size");console.assert(40===b.shentsize,"Bad section header size");[d]=read_structs(view_slice(a,b.phoff,b.phentsize*b.phnum),ProgramHeader,b.phnum);[a]=read_structs(view_slice(a,b.shoff,b.shentsize*b.shnum),SectionHeader,b.shnum);if(DEBUG&&LOG_LEVEL){console.log("%d program headers:",d.length);for(let e of d)console.log("type=%s offset=%s vaddr=%s paddr=%s filesz=%s memsz=%s flags=%s align=%s",e.type.toString(16),e.offset.toString(16),
e.vaddr.toString(16),e.paddr.toString(16),e.filesz.toString(16),e.memsz.toString(16),e.flags.toString(16),e.align.toString(16));console.log("%d program headers:",a.length);for(let e of a)console.log("name=%s type=%s flags=%s addr=%s offset=%s size=%s link=%s info=%s addralign=%s entsize=%s",e.name.toString(16),e.type.toString(16),e.flags.toString(16),e.addr.toString(16),e.offset.toString(16),e.size.toString(16),e.link.toString(16),e.info.toString(16),e.addralign.toString(16),e.entsize.toString(16))}return{header:b,
program_headers:d,sections_headers:a}}function read_struct(a,b){let c={},d=0;for(let 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 read_structs(a,b,c){let d=[],e=0;for(var g=0;g<c;g++){let [f,k]=read_struct(view_slice(a,e),b);d.push(f);e+=k}return[d,e]}function view_slice(a,b,c){return new DataView(a.buffer,a.byteOffset+b,c)};const LINUX_BOOT_HDR_SETUP_SECTS=497,LINUX_BOOT_HDR_SYSSIZE=500,LINUX_BOOT_HDR_VIDMODE=506,LINUX_BOOT_HDR_BOOT_FLAG=510,LINUX_BOOT_HDR_HEADER=514,LINUX_BOOT_HDR_VERSION=518,LINUX_BOOT_HDR_TYPE_OF_LOADER=528,LINUX_BOOT_HDR_LOADFLAGS=529,LINUX_BOOT_HDR_CODE32_START=532,LINUX_BOOT_HDR_RAMDISK_IMAGE=536,LINUX_BOOT_HDR_RAMDISK_SIZE=540,LINUX_BOOT_HDR_HEAP_END_PTR=548,LINUX_BOOT_HDR_CMD_LINE_PTR=552,LINUX_BOOT_HDR_INITRD_ADDR_MAX=556,LINUX_BOOT_HDR_KERNEL_ALIGNMENT=560,LINUX_BOOT_HDR_RELOCATABLE_KERNEL=
564,LINUX_BOOT_HDR_MIN_ALIGNMENT=565,LINUX_BOOT_HDR_XLOADFLAGS=566,LINUX_BOOT_HDR_CMDLINE_SIZE=568,LINUX_BOOT_HDR_PAYLOAD_OFFSET=584,LINUX_BOOT_HDR_PAYLOAD_LENGTH=588,LINUX_BOOT_HDR_PREF_ADDRESS=600,LINUX_BOOT_HDR_INIT_SIZE=608,LINUX_BOOT_HDR_CHECKSUM1=43605,LINUX_BOOT_HDR_CHECKSUM2=1400005704,LINUX_BOOT_HDR_TYPE_OF_LOADER_NOT_ASSIGNED=255,LINUX_BOOT_HDR_LOADFLAGS_LOADED_HIGH=1,LINUX_BOOT_HDR_LOADFLAGS_QUIET_FLAG=32,LINUX_BOOT_HDR_LOADFLAGS_KEEP_SEGMENTS=64,LINUX_BOOT_HDR_LOADFLAGS_CAN_USE_HEAPS=
128;
function load_kernel(a,b,c,d){dbg_log("Trying to load kernel of size "+b.byteLength);var e=new Uint8Array(b);const g=new Uint16Array(b),f=new Uint32Array(b);var k=e[LINUX_BOOT_HDR_SETUP_SECTS]||4,m=g[LINUX_BOOT_HDR_BOOT_FLAG>>1];if(m!==LINUX_BOOT_HDR_CHECKSUM1)dbg_log("Bad checksum1: "+h(m));else if(m=g[LINUX_BOOT_HDR_HEADER>>1]|g[LINUX_BOOT_HDR_HEADER+2>>1]<<16,m!==LINUX_BOOT_HDR_CHECKSUM2)dbg_log("Bad checksum2: "+h(m));else{m=g[LINUX_BOOT_HDR_VERSION>>1];dbg_assert(514<=m);var l=e[LINUX_BOOT_HDR_LOADFLAGS];dbg_assert(l&
LINUX_BOOT_HDR_LOADFLAGS_LOADED_HIGH);var n=g[LINUX_BOOT_HDR_XLOADFLAGS>>1],p=f[LINUX_BOOT_HDR_INITRD_ADDR_MAX>>2],t=f[LINUX_BOOT_HDR_KERNEL_ALIGNMENT>>2],r=e[LINUX_BOOT_HDR_RELOCATABLE_KERNEL],q=e[LINUX_BOOT_HDR_MIN_ALIGNMENT],v=f[LINUX_BOOT_HDR_CMDLINE_SIZE>>2],u=f[LINUX_BOOT_HDR_PAYLOAD_OFFSET>>2],x=f[LINUX_BOOT_HDR_PAYLOAD_LENGTH>>2],z=f[LINUX_BOOT_HDR_PREF_ADDRESS>>2],C=f[LINUX_BOOT_HDR_PREF_ADDRESS+4>>2],D=f[LINUX_BOOT_HDR_INIT_SIZE>>2];dbg_log("kernel boot protocol version: "+h(m));dbg_log("flags="+
h(l)+" xflags="+h(n));dbg_log("code32_start="+h(f[LINUX_BOOT_HDR_CODE32_START>>2]));dbg_log("initrd_addr_max="+h(p));dbg_log("kernel_alignment="+h(t));dbg_log("relocatable="+r);dbg_log("min_alignment="+h(q));dbg_log("cmdline max="+h(v));dbg_log("payload offset="+h(u)+" size="+h(x));dbg_log("pref_address="+h(C)+":"+h(z));dbg_log("init_size="+h(D));e[LINUX_BOOT_HDR_TYPE_OF_LOADER]=LINUX_BOOT_HDR_TYPE_OF_LOADER_NOT_ASSIGNED;e[LINUX_BOOT_HDR_LOADFLAGS]=l&~LINUX_BOOT_HDR_LOADFLAGS_QUIET_FLAG&~LINUX_BOOT_HDR_LOADFLAGS_KEEP_SEGMENTS|
LINUX_BOOT_HDR_LOADFLAGS_CAN_USE_HEAPS;g[LINUX_BOOT_HDR_HEAP_END_PTR>>1]=56832;g[LINUX_BOOT_HDR_VIDMODE>>1]=65535;dbg_log("heap_end_ptr="+h(56832));d+="\x00";dbg_assert(d.length<v);dbg_log("cmd_line_ptr="+h(581632));f[LINUX_BOOT_HDR_CMD_LINE_PTR>>2]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);k=512*(k+1);dbg_log("prot_mode_kernel_start="+h(k));d=new Uint8Array(b,0,k);b=new Uint8Array(b,k);e=k=0;c&&(k=67108864,e=c.byteLength,dbg_assert(1048576+b.length<k),a.set(new Uint8Array(c),k));
f[LINUX_BOOT_HDR_RAMDISK_IMAGE>>2]=k;f[LINUX_BOOT_HDR_RAMDISK_SIZE>>2]=e;dbg_assert(655360>524288+d.length);a.set(d,524288);a.set(b,1048576);return{option_rom:{name:"genroms/kernel.bin",data:make_linux_boot_rom(32768,57344)}}}}
function make_linux_boot_rom(a,b){const c=new Uint8Array(256);(new Uint16Array(c.buffer))[0]=43605;c[2]=1;var d=3;c[d++]=250;c[d++]=184;c[d++]=a>>0;c[d++]=a>>8;c[d++]=142;c[d++]=192;c[d++]=142;c[d++]=216;c[d++]=142;c[d++]=224;c[d++]=142;c[d++]=232;c[d++]=142;c[d++]=208;c[d++]=188;c[d++]=b>>0;c[d++]=b>>8;c[d++]=234;c[d++]=0;c[d++]=0;c[d++]=a+32>>0;c[d++]=a+32>>8;dbg_assert(512>d);a=d;b=c[a]=0;for(d=0;d<c.length;d++)b+=c[d];c[a]=-b;return c};var SHIFT_SCAN_CODE=42,SCAN_CODE_RELEASE=128;
function KeyboardAdapter(a){function b(r){!r.altKey&&k[56]&&g(56,!1);return e(r,!1)}function c(r){!r.altKey&&k[56]&&g(56,!1);return e(r,!0)}function d(r){r=Object.keys(k);for(var q,v=0;v<r.length;v++)q=+r[v],k[q]&&g(q,!1);k={}}function e(r,q){var v;if(v=m.bus)v=r.shiftKey&&r.ctrlKey&&(73===r.keyCode||74===r.keyCode||75===r.keyCode)||!m.emu_enabled?!1:r.target?r.target.classList.contains("phone_keyboard")||"INPUT"!==r.target.nodeName&&"TEXTAREA"!==r.target.nodeName:!0;if(v){a:{if(void 0!==r.code&&
(v=t[r.code],void 0!==v))break a;v=l[r.keyCode]}if(v)return g(v,q,r.repeat),r.preventDefault&&r.preventDefault(),!1;console.log("Missing char in map: keyCode="+(r.keyCode||-1).toString(16)+" code="+r.code)}}function g(r,q,v){if(q)k[r]&&!v&&g(r,!1);else if(!k[r])return;(k[r]=q)||(r|=128);255<r?(f(r>>8),f(r&255)):f(r)}function f(r){m.bus.send("keyboard-code",r)}var k={},m=this;this.emu_enabled=!0;var l=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,
57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,
0,0,0,0,0,0,0,0,0,0,0]),n={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},p={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,
72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192},t={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,
KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,
ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",b,!1),window.removeEventListener("keydown",c,!1),window.removeEventListener("blur",d,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",
b,!1),window.addEventListener("keydown",c,!1),window.addEventListener("blur",d,!1))};this.init();this.simulate_press=function(r){r={keyCode:r};e(r,!0);e(r,!1)};this.simulate_char=function(r){var q=r.charCodeAt(0);q in n?this.simulate_press(n[q]):q in p?(f(SHIFT_SCAN_CODE),this.simulate_press(p[q]),f(SHIFT_SCAN_CODE|SCAN_CODE_RELEASE)):console.log("ascii -> keyCode not found: ",q,r)}};function MouseAdapter(a,b){function c(u){if(!v.enabled||!v.emu_enabled)return!1;var x=b||document.body,z;if(!(z=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===x){z=!0;break a}u=u.parentNode}z=!1}return z}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,q=u.clientY)}function e(u){if(n||t||p)v.bus.send("mouse-click",[!1,!1,!1]),n=t=p=!1}function g(u){if(v.bus&&c(u)&&v.is_running){var x=0,z=0,C=u.changedTouches;C?C.length&&(C=C[C.length-1],x=C.clientX-
r,z=C.clientY-q,r=C.clientX,q=C.clientY,u.preventDefault()):"number"===typeof u.movementX?(x=u.movementX,z=u.movementY):"number"===typeof u.webkitMovementX?(x=u.webkitMovementX,z=u.webkitMovementY):"number"===typeof u.mozMovementX?(x=u.mozMovementX,z=u.mozMovementY):(x=u.clientX-r,z=u.clientY-q,r=u.clientX,q=u.clientY);v.bus.send("mouse-delta",[.15*x,-(.15*z)]);b&&v.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function f(u){c(u)&&m(u,!0)}function k(u){c(u)&&
m(u,!1)}function m(u,x){v.bus&&(1===u.which?n=x:2===u.which?t=x:3===u.which?p=x:dbg_log("Unknown event.which: "+u.which),v.bus.send("mouse-click",[n,t,p]),u.preventDefault())}function l(u){if(c(u)){var x=u.wheelDelta||-u.detail;0>x?x=-1:0<x&&(x=1);v.bus.send("mouse-wheel",[x,0]);u.preventDefault()}}var n=!1,p=!1,t=!1,r=0,q=0,v=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=u},this);this.is_running=!1;this.bus.register("emulator-stopped",
function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",g,!1),window.removeEventListener("mousemove",g,!1),window.removeEventListener("mousedown",f,!1),window.removeEventListener("mouseup",k,!1),window.removeEventListener("wheel",l,{passive:!1}))};this.init=function(){"undefined"!==
typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",e,!1),window.addEventListener("touchmove",g,!1),window.addEventListener("mousemove",g,!1),window.addEventListener("mousedown",f,!1),window.addEventListener("mouseup",k,!1),window.addEventListener("wheel",l,{passive:!1}))};this.init()};var DAC_QUEUE_RESERVE=.2,AUDIOBUFFER_MINIMUM_SAMPLING_RATE=8E3;
function SpeakerAdapter(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?SpeakerWorkletDAC:SpeakerBufferSourceDAC;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new SpeakerMixer(a,this.audio_context);this.pcspeaker=new PCSpeaker(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},
this);a.register("emulator-started",function(){this.audio_context.resume()},this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}SpeakerAdapter.prototype.destroy=function(){this.audio_context&&this.audio_context.close();this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close()};
function SpeakerMixer(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);
this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=
this.audio_context.createGain();this.node_merger=this.audio_context.createChannelMerger(2);this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);
a.register("mixer-connect",function(d){this.connect_source(d[0],d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],g=d[1];d=Math.pow(10,d[2]/20);var f=e===MIXER_SRC_MASTER?this:this.sources.get(e);void 0===f?dbg_assert(!1,"Mixer set volume - cannot set volume for undefined source: "+e):f.set_volume(d,g)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);
a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},this);a.register("mixer-treble-left",c(this.node_treble_left),this);a.register("mixer-treble-right",c(this.node_treble_right),this);a.register("mixer-bass-left",c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}
SpeakerMixer.prototype.add_source=function(a,b){a=new SpeakerMixerSource(this.audio_context,a,this.input_left,this.input_right);dbg_assert(!this.sources.has(b),"Mixer add source - overwritting source: "+b);this.sources.set(b,a);return a};SpeakerMixer.prototype.connect_source=function(a,b){var c=this.sources.get(a);void 0===c?dbg_assert(!1,"Mixer connect - cannot connect undefined source: "+a):c.connect(b)};
SpeakerMixer.prototype.disconnect_source=function(a,b){var c=this.sources.get(a);void 0===c?dbg_assert(!1,"Mixer disconnect - cannot disconnect undefined source: "+a):c.disconnect(b)};SpeakerMixer.prototype.set_volume=function(a,b){void 0===b&&(b=MIXER_CHANNEL_BOTH);switch(b){case MIXER_CHANNEL_LEFT:this.volume_left=a;break;case MIXER_CHANNEL_RIGHT:this.volume_right=a;break;case MIXER_CHANNEL_BOTH:this.volume_both=a;break;default:dbg_assert(!1,"Mixer set master volume - unknown channel: "+b);return}this.update()};
SpeakerMixer.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};
function SpeakerMixerSource(a,b,c,d){this.audio_context=a;this.connected_right=this.connected_left=!0;this.volume_right=this.volume_left=this.volume_both=this.gain_hidden=1;this.node_splitter=a.createChannelSplitter(2);this.node_gain_left=a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}
SpeakerMixerSource.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;this.node_gain_left.gain.setValueAtTime(this.connected_left*this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};
SpeakerMixerSource.prototype.connect=function(a){var b=!a||a===MIXER_CHANNEL_BOTH;if(b||a===MIXER_CHANNEL_LEFT)this.connected_left=!0;if(b||a===MIXER_CHANNEL_RIGHT)this.connected_right=!0;this.update()};SpeakerMixerSource.prototype.disconnect=function(a){var b=!a||a===MIXER_CHANNEL_BOTH;if(b||a===MIXER_CHANNEL_LEFT)this.connected_left=!1;if(b||a===MIXER_CHANNEL_RIGHT)this.connected_right=!1;this.update()};
SpeakerMixerSource.prototype.set_volume=function(a,b){void 0===b&&(b=MIXER_CHANNEL_BOTH);switch(b){case MIXER_CHANNEL_LEFT:this.volume_left=a;break;case MIXER_CHANNEL_RIGHT:this.volume_right=a;break;case MIXER_CHANNEL_BOTH:this.volume_both=a;break;default:dbg_assert(!1,"Mixer set volume - unknown channel: "+b);return}this.update()};SpeakerMixerSource.prototype.set_gain_hidden=function(a){this.gain_hidden=a};
function PCSpeaker(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,MIXER_SRC_PCSPEAKER);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(MIXER_SRC_PCSPEAKER)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(MIXER_SRC_PCSPEAKER)},this);a.register("pcspeaker-update",function(d){var e=
d[1],g=0;3===d[0]&&(g=1E3*OSCILLATOR_FREQ/e,g=Math.min(g,this.node_oscillator.frequency.maxValue),g=Math.max(g,0));this.node_oscillator.frequency.setValueAtTime(g,b.currentTime)},this)}PCSpeaker.prototype.start=function(){this.node_oscillator.start()};
function SpeakerWorkletDAC(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function f(l){if(0===l)return 1;l*=Math.PI;return Math.sin(l)/l}function k(){var l=Reflect.construct(AudioWorkletProcessor,[],k);l.kernel_size=3;l.queue_data=Array(1024);l.queue_start=0;l.queue_end=0;l.queue_length=0;l.queue_size=l.queue_data.length;l.queued_samples=0;l.source_buffer_previous=m;l.source_buffer_current=m;l.source_samples_per_destination=1;l.source_block_start=0;l.source_time=
0;l.source_offset=0;l.port.onmessage=n=>{switch(n.data.type){case "queue":l.queue_push(n.data.value);break;case "sampling-rate":l.source_samples_per_destination=n.data.value/sampleRate}};return l}var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(k.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(l,n,p){for(l=0;l<n[0][0].length;l++){for(var t=p=0,r=this.source_offset+this.kernel_size,
q=this.source_offset-this.kernel_size+1;q<=r;q++){var v=this.source_block_start+q;p+=this.get_sample(v,0)*this.kernel(this.source_time-q);t+=this.get_sample(v,1)*this.kernel(this.source_time-q)}if(isNaN(p)||isNaN(t))p=t=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][l]=p;n[0][1][l]=t;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=
this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};k.prototype.kernel=function(l){return f(l)*f(l/this.kernel_size)};k.prototype.get_sample=function(l,n){return 0>l?(l+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][l]):this.source_buffer_current[n][l]};k.prototype.ensure_enough_data=function(l){var n=this.source_buffer_current[0].length;n-this.source_block_start<l&&(this.prepare_next_buffer(),this.source_block_start-=n)};k.prototype.prepare_next_buffer=
function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var l=this.source_buffer_current[0].length;if(256>l){for(var n=this.queue_start,p=0;256>l&&p<this.queue_length;)l+=this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;l=Math.max(l,256);l=[new Float32Array(l),new Float32Array(l)];l[0].set(this.source_buffer_current[0]);
l[1].set(this.source_buffer_current[1]);n=this.source_buffer_current[0].length;for(var t=0;t<p;t++){var r=this.queue_shift();l[0].set(r[0],n);l[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=l}this.pump()};k.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(l){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=l,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,
this.queued_samples+=l[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return m;var l=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=l[0].length;return l};k.prototype.dbg_log=function(l){DEBUG&&this.port.postMessage({type:"debug-log",value:l})};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,
e);DEBUG&&(b="var DEBUG = true;\n"+b);b=new Blob([b],{type:"application/javascript"});var g=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();this.audio_context.audioWorklet.addModule(g).then(()=>{URL.revokeObjectURL(g);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});
this.node_processor.port.onmessage=f=>{switch(f.data.type){case "pump":this.pump();break;case "debug-log":dbg_log("SpeakerWorkletDAC - Worklet: "+f.data.value)}};this.node_processor.connect(this.node_output)});this.mixer_connection=c.add_source(this.node_output,MIXER_SRC_DAC);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(f){this.queue(f)},this);a.register("dac-enable",function(f){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",
function(f){dbg_assert(0<f,"Sampling rate should be nonzero");this.sampling_rate=f;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:f})},this);DEBUG&&(this.debugger=new SpeakerDACDebugger(this.audio_context,this.node_output))}SpeakerWorkletDAC.prototype.queue=function(a){this.node_processor&&(DEBUG&&this.debugger.push_queued_data(a),this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};
SpeakerWorkletDAC.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};
function SpeakerBufferSourceDAC(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=this.node_lowpass;this.mixer_connection=c.add_source(this.node_output,MIXER_SRC_DAC);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(d){this.enabled=!0;this.pump()},
this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){dbg_assert(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(AUDIOBUFFER_MINIMUM_SAMPLING_RATE/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this);DEBUG&&(this.debugger=new SpeakerDACDebugger(this.audio_context,this.node_output))}
SpeakerBufferSourceDAC.prototype.queue=function(a){DEBUG&&this.debugger.push_queued_data(a);var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),g=d.getChannelData(1),f=0,k=0;k<b;k++)for(var m=0;m<this.rate_ratio;m++,f++)e[f]=a[0][k],g[f]=a[1][k]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],
1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(dbg_log("Speaker DAC - Creating/Recreating reserve - shouldn't occur frequently during playback"),this.buffered_time=d,d=DAC_QUEUE_RESERVE-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)};SpeakerBufferSourceDAC.prototype.pump=function(){this.enabled&&(this.buffered_time-this.audio_context.currentTime>DAC_QUEUE_RESERVE||this.bus.send("dac-request-data"))};
function SpeakerDACDebugger(a,b){this.audio_context=a;this.node_source=b;this.node_processor=null;this.node_gain=this.audio_context.createGain();this.node_gain.gain.setValueAtTime(0,this.audio_context.currentTime);this.node_gain.connect(this.audio_context.destination);this.is_active=!1;this.queued_history=[];this.output_history=[];this.queued=[[],[]];this.output=[[],[]]}
SpeakerDACDebugger.prototype.start=function(a){this.is_active=!0;this.queued=[[],[]];this.output=[[],[]];this.queued_history.push(this.queued);this.output_history.push(this.output);this.node_processor=this.audio_context.createScriptProcessor(1024,2,2);this.node_processor.onaudioprocess=b=>{this.output[0].push(b.inputBuffer.getChannelData(0).slice());this.output[1].push(b.inputBuffer.getChannelData(1).slice())};this.node_source.connect(this.node_processor);this.node_processor.connect(this.node_gain);
setTimeout(()=>{this.stop()},a)};SpeakerDACDebugger.prototype.stop=function(){this.is_active=!1;this.node_source.disconnect(this.node_processor);this.node_processor.disconnect();this.node_processor=null};SpeakerDACDebugger.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].push(a[0].slice()),this.queued[1].push(a[1].slice()))};SpeakerDACDebugger.prototype.download_txt=function(a,b){a=this.output_history[a][b].map(c=>c.join(" ")).join(" ");dump_file(a,"dacdata.txt")};
SpeakerDACDebugger.prototype.download_csv=function(a){a=this.output_history[a];for(var b=[],c=0;c<a[0].length;c++)for(var d=0;d<a[0][c].length;d++)b.push(`${a[0][c][d]},${a[1][c][d]}`);dump_file(b.join("\n"),"dacdata.csv")};function SerialAdapter(a,b){function c(k){f.bus&&f.enabled&&(f.send_char(k.which),k.preventDefault())}function d(k){var m=k.which;8===m?(f.send_char(127),k.preventDefault()):9===m&&(f.send_char(9),k.preventDefault())}function e(k){if(f.enabled){for(var m=k.clipboardData.getData("text/plain"),l=0;l<m.length;l++)f.send_char(m.charCodeAt(l));k.preventDefault()}}function g(k){k.target!==a&&a.blur()}var f=this;this.enabled=!0;this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-char",
function(k){this.show_char(k)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",g,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",g,!1)};this.init();this.show_char=function(k){"\b"===k?(this.text=this.text.slice(0,
-1),this.update()):"\r"!==k&&(this.text+=k,"\n"===k&&(this.text_new_line=!0),this.update())};this.update=function(){var k=Date.now(),m=k-this.last_update;16>m?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;var l=Date.now();dbg_assert(15<=l-this.last_update);this.last_update=l;this.render()},16-m)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=k,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(k){f.bus&&f.bus.send("serial0-input",k)}}function SerialRecordingAdapter(a){this.text="";a.register("serial0-output-char",function(b){this.text+=b},this)}
function SerialAdapterXtermJS(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal;c.setOption("logLevel","off");c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let g=0;g<e.length;g++)b.send("serial0-input",e.charCodeAt(g))});b.register("serial0-output-char",function(e){c.write(e)},this);this.destroy=function(){d.dispose();c.dispose()}}}SerialAdapterXtermJS.prototype.show=function(){this.term&&this.term.open(this.element)};function NetworkAdapter(a,b){this.bus=b;this.socket=void 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.bus.register("net0-send",function(c){this.send(c)},this)}NetworkAdapter.prototype.handle_message=function(a){this.bus&&this.bus.send("net0-receive",new Uint8Array(a.data))};NetworkAdapter.prototype.handle_close=function(a){this.connect();setTimeout(this.connect.bind(this),this.reconnect_interval)};
NetworkAdapter.prototype.handle_open=function(a){for(a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};NetworkAdapter.prototype.handle_error=function(a){};NetworkAdapter.prototype.destroy=function(){this.socket&&this.socket.close()};
NetworkAdapter.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();this.last_connect_attempt+this.reconnect_interval>a||(this.last_connect_attempt=Date.now(),this.socket=new WebSocket(this.url),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))}};
NetworkAdapter.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())};NetworkAdapter.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};function V86Starter(a){this.cpu_is_running=!1;var b=Bus.create();this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:WASM_TABLE_SIZE+WASM_TABLE_OFFSET});b={cpu_exception_hook:f=>this.cpu_exception_hook&&this.cpu_exception_hook(f),hlt_op:function(){return c.hlt_op()},abort:function(){dbg_assert(!1)},microtick:v86.microtick,get_rand_int:function(){return v86util.get_rand_int()},pic_acknowledge:function(){c.pic_acknowledge()},io_port_read8:function(f){return c.io.port_read8(f)},
io_port_read16:function(f){return c.io.port_read16(f)},io_port_read32:function(f){return c.io.port_read32(f)},io_port_write8:function(f,k){c.io.port_write8(f,k)},io_port_write16:function(f,k){c.io.port_write16(f,k)},io_port_write32:function(f,k){c.io.port_write32(f,k)},mmap_read8:function(f){return c.mmap_read8(f)},mmap_read16:function(f){return c.mmap_read16(f)},mmap_read32:function(f){return c.mmap_read32(f)},mmap_write8:function(f,k){c.mmap_write8(f,k)},mmap_write16:function(f,k){c.mmap_write16(f,
k)},mmap_write32:function(f,k){c.mmap_write32(f,k)},mmap_write64:function(f,k,m){c.mmap_write64(f,k,m)},mmap_write128:function(f,k,m,l,n){c.mmap_write128(f,k,m,l,n)},log_from_wasm:function(f,k){f=v86util.read_sized_string_from_mem(d,f,k);dbg_log(f,LOG_CPU)},console_log_from_wasm:function(f,k){f=v86util.read_sized_string_from_mem(d,f,k);console.error(f)},dbg_trace_from_wasm:function(){dbg_trace(LOG_CPU)},codegen_finalize:(f,k,m,l,n)=>{c.codegen_finalize(f,k,m,l,n)},jit_clear_func:f=>c.jit_clear_func(f),
jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let g=a.wasm_fn;g||(g=f=>new Promise(k=>{let m=DEBUG?"v86-debug.wasm":"v86.wasm",l="v86-fallback.wasm";if(a.wasm_path){m=a.wasm_path;const n=m.lastIndexOf("/");l=(-1===n?"":m.substr(0,n))+"/"+l}else"undefined"===typeof window&&"string"===typeof __dirname?(m=__dirname+"/"+m,l=__dirname+"/"+l):(m="build/"+m,l="build/"+l);v86util.load_file(m,{done:async n=>{try{const {instance:p}=await WebAssembly.instantiate(n,f);k(p.exports)}catch(p){v86util.load_file(l,
{done:async t=>{({instance:t}=await WebAssembly.instantiate(t,f));k(t.exports)}})}},progress:n=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,file_name:m,lengthComputable:n.lengthComputable,total:n.total,loaded:n.loaded})}})}));g({env:b}).then(f=>{d=f.memory;f.rust_init();f=this.v86=new v86(this.emulator_bus,{exports:f,wasm_table:e});c=f.cpu;this.continue_init(f,a)})}
V86Starter.prototype.continue_init=async function(a,b){function c(r,q){switch(r){case "hda":g.hda=this.disk_images.hda=q;break;case "hdb":g.hdb=this.disk_images.hdb=q;break;case "cdrom":g.cdrom=this.disk_images.cdrom=q;break;case "fda":g.fda=this.disk_images.fda=q;break;case "fdb":g.fdb=this.disk_images.fdb=q;break;case "multiboot":g.multiboot=this.disk_images.multiboot=q.buffer;break;case "bzimage":g.bzimage=this.disk_images.bzimage=q.buffer;break;case "initrd":g.initrd=this.disk_images.initrd=q.buffer;
break;case "bios":g.bios=q.buffer;break;case "vga_bios":g.vga_bios=q.buffer;break;case "initial_state":g.initial_state=q.buffer;break;case "fs9p_json":g.fs9p_json=q;break;default:dbg_assert(!1,r)}}function d(r,q){if(q)if(q.get&&q.set&&q.load)f.push({name:r,loadable:q});else{if("bios"===r||"vga_bios"===r||"initial_state"===r||"multiboot"===r||"bzimage"===r||"initrd"===r)q.async=!1;q.buffer instanceof ArrayBuffer?(q=new v86util.SyncBuffer(q.buffer),f.push({name:r,loadable:q})):"undefined"!==typeof File&&
q.buffer instanceof File?(void 0===q.async&&(q.async=268435456<=q.buffer.size),q=q.async?new v86util.AsyncFileBuffer(q.buffer):new v86util.SyncFileBuffer(q.buffer),f.push({name:r,loadable:q})):q.url?q.async?(q=q.use_parts?new v86util.AsyncXHRPartfileBuffer(q.url,q.size,q.fixed_chunk_size):new v86util.AsyncXHRBuffer(q.url,q.size,q.fixed_chunk_size),f.push({name:r,loadable:q})):f.push({name:r,url:q.url,size:q.size}):dbg_log("Ignored file: url="+q.url+" buffer="+q.buffer)}}async function e(){if(g.fs9p&&
g.fs9p_json){if(g.initial_state?dbg_log("Filesystem basefs ignored: Overridden by state image"):g.fs9p.load_from_json(g.fs9p_json),b.bzimage_initrd_from_filesystem){const {bzimage_path:r,initrd_path:q}=this.get_bzimage_initrd_from_filesystem(g.fs9p);dbg_log("Found bzimage: "+r+" and initrd: "+q);const [v,u]=await Promise.all([g.fs9p.read_file(q),g.fs9p.read_file(r)]);c.call(this,"initrd",new v86util.SyncBuffer(v.buffer));c.call(this,"bzimage",new v86util.SyncBuffer(u.buffer))}}else dbg_assert(!b.bzimage_initrd_from_filesystem,
"bzimage_initrd_from_filesystem: Requires a filesystem");this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.bus.send("cpu-init",g);g.initial_state&&(a.restore_state(g.initial_state),g.initial_state=void 0);b.autostart&&this.bus.send("cpu-run");this.emulator_bus.send("emulator-loaded")}this.bus.register("emulator-stopped",function(){this.cpu_is_running=!1},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0},this);var g={};this.disk_images={fda:void 0,
fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};g.acpi=b.acpi;g.load_devices=!0;g.log_level=b.log_level;g.memory_size=b.memory_size||67108864;g.vga_memory_size=b.vga_memory_size||8388608;g.boot_order=b.boot_order||531;g.fastboot=b.fastboot||!1;g.fda=void 0;g.fdb=void 0;g.uart1=b.uart1;g.uart2=b.uart2;g.uart3=b.uart3;g.cmdline=b.cmdline;g.preserve_mac_from_state_image=b.preserve_mac_from_state_image;g.mac_address_translation=b.mac_address_translation;g.cpuid_level=b.cpuid_level;b.network_adapter?this.network_adapter=
b.network_adapter(this.bus):b.network_relay_url&&(this.network_adapter=new NetworkAdapter(b.network_relay_url,this.bus));g.enable_ne2k=!0;b.disable_keyboard||(this.keyboard_adapter=new KeyboardAdapter(this.bus));b.disable_mouse||(this.mouse_adapter=new MouseAdapter(this.bus,b.screen_container));b.screen_container?this.screen_adapter=new ScreenAdapter(b.screen_container,this.bus):b.screen_dummy&&(this.screen_adapter=new DummyScreenAdapter(this.bus));b.serial_container&&(this.serial_adapter=new SerialAdapter(b.serial_container,
this.bus));b.serial_container_xtermjs&&(this.serial_adapter=new SerialAdapterXtermJS(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new SpeakerAdapter(this.bus));var f=[];b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");for(var k="bios vga_bios cdrom hda hdb fda fdb initial_state multiboot bzimage initrd".split(" "),m=0;m<k.length;m++)d(k[m],b[k[m]]);if(b.filesystem){k=b.filesystem.basefs;m=b.filesystem.baseurl;let r=new MemoryFileStorage;
m&&(r=new ServerFileStorageWrapper(r,m));g.fs9p=this.fs9p=new FS(r);if(k){dbg_assert(m,"Filesystem: baseurl must be specified");if("object"===typeof k){var l=k.size;k=k.url}dbg_assert("string"===typeof k);f.push({name:"fs9p_json",url:k,size:l,as_json:!0})}}var n=this,p=f.length,t=function(r){if(r===p)setTimeout(e.bind(this),0);else{var q=f[r];q.loadable?(q.loadable.onload=function(v){c.call(this,q.name,q.loadable);t(r+1)}.bind(this),q.loadable.load()):v86util.load_file(q.url,{done:function(v){c.call(this,
q.name,q.as_json?v:new v86util.SyncBuffer(v));t(r+1)}.bind(this),progress:function(v){200===v.target.status?n.emulator_bus.send("download-progress",{file_index:r,file_count:p,file_name:q.url,lengthComputable:v.lengthComputable,total:v.total||q.size,loaded:v.loaded}):n.emulator_bus.send("download-error",{file_index:r,file_count:p,file_name:q.url,request:v.target})},as_json:q.as_json})}}.bind(this);t(0)};
V86Starter.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).map(e=>"/"+e);a=(a.read_dir("/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(let e of[].concat(b,a)){const g=/old/i.test(e)||/fallback/i.test(e),f=/vmlinuz/i.test(e)||/bzimage/i.test(e),k=/initrd/i.test(e)||/initramfs/i.test(e);!f||d&&g||(d=e);!k||c&&g||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{initrd_path:c,
bzimage_path:d}};V86Starter.prototype.run=async function(){this.bus.send("cpu-run")};goog.exportProperty(V86Starter.prototype,"run",V86Starter.prototype.run);V86Starter.prototype.stop=async function(){this.cpu_is_running&&await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.bus.send("cpu-stop")})};goog.exportProperty(V86Starter.prototype,"stop",V86Starter.prototype.stop);
V86Starter.prototype.destroy=async function(){await this.stop();this.v86.destroy();this.keyboard_adapter&&this.keyboard_adapter.destroy();this.network_adapter&&this.network_adapter.destroy();this.mouse_adapter&&this.mouse_adapter.destroy();this.screen_adapter&&this.screen_adapter.destroy();this.serial_adapter&&this.serial_adapter.destroy();this.speaker_adapter&&this.speaker_adapter.destroy()};goog.exportProperty(V86Starter.prototype,"destroy",V86Starter.prototype.destroy);
V86Starter.prototype.restart=function(){this.bus.send("cpu-restart")};goog.exportProperty(V86Starter.prototype,"restart",V86Starter.prototype.restart);V86Starter.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};goog.exportProperty(V86Starter.prototype,"add_listener",V86Starter.prototype.add_listener);V86Starter.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};goog.exportProperty(V86Starter.prototype,"remove_listener",V86Starter.prototype.remove_listener);
V86Starter.prototype.restore_state=async function(a){dbg_assert(1===arguments.length);this.v86.restore_state(a)};goog.exportProperty(V86Starter.prototype,"restore_state",V86Starter.prototype.restore_state);V86Starter.prototype.save_state=async function(){dbg_assert(0===arguments.length);return this.v86.save_state()};goog.exportProperty(V86Starter.prototype,"save_state",V86Starter.prototype.save_state);
V86Starter.prototype.get_statistics=function(){console.warn("V86Starter.prototype.get_statistics is deprecated. Use events instead.");var a={cpu:{instruction_counter:this.get_instruction_counter()}};if(!this.v86)return a;var b=this.v86.cpu.devices;b.hda&&(a.hda=b.hda.stats);b.cdrom&&(a.cdrom=b.cdrom.stats);b.ps2&&(a.mouse={enabled:b.ps2.use_mouse});b.vga&&(a.vga={is_graphical:b.vga.stats.is_graphical});return a};goog.exportProperty(V86Starter.prototype,"get_statistics",V86Starter.prototype.get_statistics);
V86Starter.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};goog.exportProperty(V86Starter.prototype,"get_instruction_counter",V86Starter.prototype.get_instruction_counter);V86Starter.prototype.is_running=function(){return this.cpu_is_running};goog.exportProperty(V86Starter.prototype,"is_running",V86Starter.prototype.is_running);V86Starter.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};
goog.exportProperty(V86Starter.prototype,"keyboard_send_scancodes",V86Starter.prototype.keyboard_send_scancodes);V86Starter.prototype.keyboard_send_keys=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};goog.exportProperty(V86Starter.prototype,"keyboard_send_keys",V86Starter.prototype.keyboard_send_keys);V86Starter.prototype.keyboard_send_text=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};
goog.exportProperty(V86Starter.prototype,"keyboard_send_text",V86Starter.prototype.keyboard_send_text);V86Starter.prototype.screen_make_screenshot=function(){this.screen_adapter&&this.screen_adapter.make_screenshot()};goog.exportProperty(V86Starter.prototype,"screen_make_screenshot",V86Starter.prototype.screen_make_screenshot);V86Starter.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};goog.exportProperty(V86Starter.prototype,"screen_set_scale",V86Starter.prototype.screen_set_scale);
V86Starter.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};goog.exportProperty(V86Starter.prototype,"screen_go_fullscreen",V86Starter.prototype.screen_go_fullscreen);
V86Starter.prototype.lock_mouse=function(){var a=document.body,b=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock;b&&b.call(a)};goog.exportProperty(V86Starter.prototype,"lock_mouse",V86Starter.prototype.lock_mouse);V86Starter.prototype.mouse_set_status=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};V86Starter.prototype.keyboard_set_status=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};
goog.exportProperty(V86Starter.prototype,"keyboard_set_status",V86Starter.prototype.keyboard_set_status);V86Starter.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};goog.exportProperty(V86Starter.prototype,"serial0_send",V86Starter.prototype.serial0_send);V86Starter.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};goog.exportProperty(V86Starter.prototype,"serial_send_bytes",V86Starter.prototype.serial_send_bytes);
V86Starter.prototype.mount_fs=async function(a,b,c,d){let e=new MemoryFileStorage;b&&(e=new ServerFileStorageWrapper(e,b));const g=new FS(e,this.fs9p.qidcounter),f=()=>{const k=this.fs9p.Mount(a,g);d&&(k===-ENOENT?d(new FileNotFoundError):k===-EEXIST?d(new FileExistsError):0>k?(dbg_assert(!1,"Unexpected error code: "+-k),d(Error("Failed to mount. Error number: "+-k))):d(null))};b?(dbg_assert("object"===typeof c,"Filesystem: basefs must be a JSON object"),g.load_from_json(c,()=>f())):f()};
goog.exportProperty(V86Starter.prototype,"mount_fs",V86Starter.prototype.mount_fs);V86Starter.prototype.create_file=async function(a,b){dbg_assert(2===arguments.length);var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];var e=c.SearchPath(a).parentid;if(""!==d&&-1!==e)await c.CreateBinaryFile(d,e,b);else return Promise.reject(new FileNotFoundError)}};goog.exportProperty(V86Starter.prototype,"create_file",V86Starter.prototype.create_file);
V86Starter.prototype.read_file=async function(a){dbg_assert(1===arguments.length);var b=this.fs9p;if(b)return(b=await b.read_file(a))?b:Promise.reject(new FileNotFoundError)};goog.exportProperty(V86Starter.prototype,"read_file",V86Starter.prototype.read_file);
V86Starter.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);if(d.sleep)setTimeout(()=>b(e),1E3*d.sleep);else if(d.vga_text){const g=this.screen_adapter.get_text_screen();for(let f of g)if(f.includes(d.vga_text)){b(e);return}setTimeout(()=>b(c),1E3)}else d.keyboard_send?(d.keyboard_send instanceof Array?this.keyboard_send_scancodes(d.keyboard_send):(dbg_assert("string"===typeof d.keyboard_send),this.keyboard_send_text(d.keyboard_send)),b(e)):d.call?(d.call(),b(e)):
dbg_assert(!1,d)}};b(a)};V86Starter.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};V86Starter.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};function FileExistsError(a){this.message=a||"File already exists"}FileExistsError.prototype=Error.prototype;function FileNotFoundError(a){this.message=a||"File not found"}FileNotFoundError.prototype=Error.prototype;
"undefined"!==typeof window?(window.V86Starter=V86Starter,window.V86=V86Starter):"undefined"!==typeof module&&"undefined"!==typeof module.exports?(module.exports.V86Starter=V86Starter,module.exports.V86=V86Starter):"function"===typeof importScripts&&(self.V86Starter=V86Starter,self.V86=V86Starter);var WorkerBus={Connector:function(a){this.listeners={};this.pair=a;a.addEventListener("message",function(b){b=b.data;for(var c=this.listeners[b[0]],d=0;d<c.length;d++){var e=c[d];e.fn.call(e.this_value,b[1])}}.bind(this),!1)}};WorkerBus.Connector.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};WorkerBus.Connector.prototype.send=function(a,b,c){dbg_assert(1<=arguments.length);this.pair&&this.pair.postMessage([a,b],c)};
WorkerBus.init=function(a){return new WorkerBus.Connector(a)};function DummyScreenAdapter(a){var b,c,d,e,g;this.bus=a;a.register("screen-set-mode",function(f){this.set_mode(f)},this);a.register("screen-fill-buffer-end",function(f){this.update_buffer(f[0],f[1])},this);a.register("screen-put-char",function(f){this.put_char(f[0],f[1],f[2],f[3],f[4])},this);a.register("screen-text-scroll",function(f){console.log("scroll",f)},this);a.register("screen-update-cursor",function(f){this.update_cursor(f[0],f[1])},this);a.register("screen-update-cursor-scanline",function(f){this.update_cursor_scanline(f[0],
f[1])},this);a.register("screen-set-size-text",function(f){this.set_size_text(f[0],f[1])},this);a.register("screen-set-size-graphical",function(f){this.set_size_graphical(f[0],f[1])},this);this.put_char=function(f,k,m,l,n){f<g&&k<e&&(f=3*(f*e+k),d[f]=m,d[f+1]=l,d[f+2]=n)};this.destroy=function(){};this.set_mode=function(f){};this.clear_screen=function(){};this.set_size_text=function(f,k){if(f!==e||k!==g)d=new Int32Array(f*k*3),e=f,g=k};this.set_size_graphical=function(f,k){};this.set_scale=function(f,
k){};this.update_cursor_scanline=function(f,k){};this.update_cursor=function(f,k){if(f!==b||k!==c)b=f,c=k};this.update_buffer=function(f,k){};this.get_text_screen=function(){for(var f=[],k=0;k<g;k++)f.push(this.get_text_row(k));return f};this.get_text_row=function(f){var k="";f=3*f*e;for(var m=0;m<e;m++)k+=String.fromCharCode(d[f+3*m]);return k}};const print_stats={stats_to_string:function(a){return print_stats.print_misc_stats(a)+print_stats.print_instruction_counts(a)},print_misc_stats:function(a){let b="";var c="COMPILE COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_SUCCESS COMPILE_WRONG_ADDRESS_SPACE COMPILE_CUT_OFF_AT_END_OF_PAGE COMPILE_WITH_LOOP_SAFETY COMPILE_PAGE COMPILE_PAGE/COMPILE_SUCCESS COMPILE_PAGE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_BASIC_BLOCK COMPILE_DUPLICATED_BASIC_BLOCK COMPILE_WASM_BLOCK COMPILE_WASM_LOOP COMPILE_DISPATCHER COMPILE_ENTRY_POINT COMPILE_WASM_TOTAL_BYTES COMPILE_WASM_TOTAL_BYTES/COMPILE_PAGE JIT_CACHE_OVERRIDE JIT_CACHE_OVERRIDE_DIFFERENT_STATE_FLAGS RUN_INTERPRETED RUN_INTERPRETED_PENDING RUN_INTERPRETED_NEAR_END_OF_PAGE RUN_INTERPRETED_DIFFERENT_STATE RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED RUN_INTERPRETED_MISSED_COMPILED_ENTRY_LOOKUP RUN_INTERPRETED_STEPS RUN_FROM_CACHE RUN_FROM_CACHE_STEPS RUN_FROM_CACHE_STEPS/RUN_FROM_CACHE RUN_FROM_CACHE_STEPS/RUN_INTERPRETED_STEPS DIRECT_EXIT INDIRECT_JUMP INDIRECT_JUMP_NO_ENTRY NORMAL_PAGE_CHANGE NORMAL_FALLTHRU NORMAL_FALLTHRU_WITH_TARGET_BLOCK NORMAL_BRANCH NORMAL_BRANCH_WITH_TARGET_BLOCK CONDITIONAL_JUMP CONDITIONAL_JUMP_PAGE_CHANGE CONDITIONAL_JUMP_EXIT CONDITIONAL_JUMP_FALLTHRU CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK CONDITIONAL_JUMP_BRANCH CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK DISPATCHER_SMALL DISPATCHER_LARGE LOOP LOOP_SAFETY CONDITION_OPTIMISED CONDITION_UNOPTIMISED FAILED_PAGE_CHANGE SAFE_READ_FAST SAFE_READ_SLOW_PAGE_CROSSED SAFE_READ_SLOW_NOT_VALID SAFE_READ_SLOW_NOT_USER SAFE_READ_SLOW_IN_MAPPED_RANGE SAFE_WRITE_FAST SAFE_WRITE_SLOW_PAGE_CROSSED SAFE_WRITE_SLOW_NOT_VALID SAFE_WRITE_SLOW_NOT_USER SAFE_WRITE_SLOW_IN_MAPPED_RANGE SAFE_WRITE_SLOW_READ_ONLY SAFE_WRITE_SLOW_HAS_CODE SAFE_READ_WRITE_FAST SAFE_READ_WRITE_SLOW_PAGE_CROSSED SAFE_READ_WRITE_SLOW_NOT_VALID SAFE_READ_WRITE_SLOW_NOT_USER SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE SAFE_READ_WRITE_SLOW_READ_ONLY SAFE_READ_WRITE_SLOW_HAS_CODE PAGE_FAULT TLB_MISS DO_RUN DO_MANY_CYCLES CYCLE_INTERNAL INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE INVALIDATE_MODULE_DIRTY_PAGE INVALIDATE_PAGE_HAD_CODE INVALIDATE_PAGE_HAD_ENTRY_POINTS DIRTY_PAGE_DID_NOT_HAVE_CODE RUN_FROM_CACHE_EXIT_SAME_PAGE RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE CLEAR_TLB FULL_CLEAR_TLB TLB_FULL TLB_GLOBAL_FULL MODRM_SIMPLE_REG MODRM_SIMPLE_REG_WITH_OFFSET MODRM_SIMPLE_CONST_OFFSET MODRM_COMPLEX SEG_OFFSET_OPTIMISED SEG_OFFSET_NOT_OPTIMISED".split(" "),
d=0;const e={};for(let f=0;f<c.length;f++){const k=c[f];var g=void 0;if(k.includes("/")){d++;const [m,l]=k.split("/");g=e[m]/e[l]}else g=e[k]=a.wm.exports.profiler_stat_get(f-d),g=1E8<=g?Math.round(g/1E6)+"m":1E5<=g?Math.round(g/1E3)+"k":g;b+=k+"="+g+"\n"}b+="\n";c=a.wm.exports.get_valid_tlb_entries_count();d=a.wm.exports.get_valid_global_tlb_entries_count();b=b+("TLB_ENTRIES="+c+" ("+d+" global, "+(c-d)+" non-global)\nWASM_TABLE_FREE=")+(a.wm.exports.jit_get_wasm_table_index_free_list_count()+"\n");
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="do_many_cycles avg: "+(a.do_many_cycles_total/a.do_many_cycles_count||0)+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nMAX_PAGES="+(a.wm.exports.get_config(0)+"\n");b+="JIT_USE_LOOP_SAFETY="+a.wm.exports.get_config(1)+"\n";return b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_config(2)+"\n"},print_instruction_counts:function(a){return[print_stats.print_instruction_counts_offset(a,
!1,!1,!1,!1),print_stats.print_instruction_counts_offset(a,!0,!1,!1,!1),print_stats.print_instruction_counts_offset(a,!1,!0,!1,!1),print_stats.print_instruction_counts_offset(a,!1,!1,!0,!1),print_stats.print_instruction_counts_offset(a,!1,!1,!1,!0)].join("\n\n")},print_instruction_counts_offset:function(a,b,c,d,e){let g="";var f=[],k=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(let t of[!1,!0]){var m=a.wm.exports.get_opstats_buffer(b,
c,d,e,n,!1,t,p);f.push({opcode:n,count:m,is_mem:t,fixed_g:p});m=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,t,p);f.push({opcode:3840|n,count:m,is_mem:t,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(let {count:n,opcode:p}of f)b.has(p)||(a+=n);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(let {opcode:n,count:p}of f)3840==(n&65280)?b[n&255]+=p:c[n&255]+=p;g=g+"------------------\nTotal: "+(a+"\n");const l=1E7<a?1E3:1;d=Math.max.apply(Math,f.map(({count:n})=>
Math.round(n/l)));d=String(d).length;g+=`Instruction counts ${k} (in ${l}):\n`;for(e=0;256>e;e++)g+=e.toString(16).padStart(2,"0")+":"+v86util.pads(Math.round(c[e]/l),d),g=15==e%16?g+"\n":g+" ";g=g+"\n"+`Instruction counts ${k} (0f, in ${l}):\n`;for(k=0;256>k;k++)g+=(k&255).toString(16).padStart(2,"0")+":"+v86util.pads(Math.round(b[k]/l),d),g=15==k%16?g+"\n":g+" ";g+="\n";f=f.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(let {opcode:n,is_mem:p,fixed_g:t,count:r}of f.slice(0,200))f=n.toString(16)+
"_"+t+(p?"_m":"_r"),g+=f+":"+(r/a*100).toFixed(2)+" ";return g+"\n"}};"undefined"!==typeof module&&"undefined"!==typeof module.exports&&(module.exports.print_stats=print_stats);function FileStorageInterface(){}FileStorageInterface.prototype.read=function(a,b,c){};FileStorageInterface.prototype.cache=function(a,b){};FileStorageInterface.prototype.uncache=function(a){};function MemoryFileStorage(){this.filedata=new Map}MemoryFileStorage.prototype.read=async function(a,b,c){dbg_assert(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?a.subarray(b,b+c):null};
MemoryFileStorage.prototype.cache=async function(a,b){dbg_assert(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,b)};MemoryFileStorage.prototype.uncache=function(a){this.filedata.delete(a)};function ServerFileStorageWrapper(a,b){dbg_assert(b,"ServerMemoryFileStorage: baseurl should not be empty");this.storage=a;this.baseurl=b}
ServerFileStorageWrapper.prototype.load_from_server=function(a){return new Promise((b,c)=>{v86util.load_file(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);await this.cache(a,d);b(d)}})})};ServerFileStorageWrapper.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};ServerFileStorageWrapper.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};ServerFileStorageWrapper.prototype.uncache=function(a){this.storage.uncache(a)};
"undefined"!==typeof window?(window.MemoryFileStorage=MemoryFileStorage,window.ServerFileStorageWrapper=ServerFileStorageWrapper):"undefined"!==typeof module&&"undefined"!==typeof module.exports?(module.exports.MemoryFileStorage=MemoryFileStorage,module.exports.ServerFileStorageWrapper=ServerFileStorageWrapper):"function"===typeof importScripts&&(self.MemoryFileStorage=MemoryFileStorage,self.ServerFileStorageWrapper=ServerFileStorageWrapper);var S_IRWXUGO=511,S_IFMT=61440,S_IFSOCK=49152,S_IFLNK=40960,S_IFREG=32768,S_IFBLK=24576,S_IFDIR=16384,S_IFCHR=8192,O_RDONLY=0,O_WRONLY=1,O_RDWR=2,O_ACCMODE=3,STATUS_INVALID=-1,STATUS_OK=0,STATUS_ON_STORAGE=2,STATUS_UNLINKED=4,STATUS_FORWARDING=5,JSONFS_VERSION=3,JSONFS_IDX_NAME=0,JSONFS_IDX_SIZE=1,JSONFS_IDX_MTIME=2,JSONFS_IDX_MODE=3,JSONFS_IDX_UID=4,JSONFS_IDX_GID=5,JSONFS_IDX_TARGET=6,JSONFS_IDX_SHA256=6;
function FS(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}FS.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&S_IFDIR)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};
FS.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new Inode(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};
FS.prototype.AddEvent=function(a,b){var c=this.inodes[a];c.status==STATUS_OK||c.status==STATUS_ON_STORAGE?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};FS.prototype.HandleEvent=function(a){var b=this.inodes[a];this.is_forwarder(b)&&this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=0;c<this.events.length;c++)this.events[c].id==a?this.events[c].OnEvent():b.push(this.events[c]);this.events=b};
FS.prototype.load_from_json=function(a,b){dbg_assert(a,"Invalid fs passed to load_from_json");if(a.version!==JSONFS_VERSION)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";var c=a.fsroot;this.used_size=a.size;for(a=0;a<c.length;a++)this.LoadRecursive(c[a],0);b&&b()};
FS.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[JSONFS_IDX_NAME];c.size=a[JSONFS_IDX_SIZE];c.mtime=a[JSONFS_IDX_MTIME];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[JSONFS_IDX_MODE];c.uid=a[JSONFS_IDX_UID];c.gid=a[JSONFS_IDX_GID];var e=c.mode&S_IFMT;e===S_IFDIR?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[JSONFS_IDX_TARGET])):e===S_IFREG?(c.status=STATUS_ON_STORAGE,c.sha256sum=a[JSONFS_IDX_SHA256],dbg_assert(c.sha256sum),this.PushInode(c,b,d)):e===S_IFLNK?(c.symlink=
a[JSONFS_IDX_TARGET],this.PushInode(c,b,d)):e!==S_IFSOCK&&dbg_log("Unexpected ifmt: "+h(e)+" ("+d+")")};FS.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};FS.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};
FS.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];dbg_assert(!this.is_forwarder(e),"Filesystem: Shouldn't link under fowarder parents");dbg_assert(this.IsDirectory(a),"Filesystem: Can't link under non-directories");dbg_assert(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");dbg_assert(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks);dbg_assert(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");
e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(dbg_assert(!d.direntries.has(".."),"Filesystem: Cannot link a directory twice"),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};
FS.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];dbg_assert(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");dbg_assert(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(dbg_assert(d.direntries.get("..")===a,"Filesystem: Found directory with bad parent id"),d.direntries.delete(".."),e.nlinks--),dbg_assert(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+
d.nlinks)):dbg_assert(!1,"Filesystem: Can't unlink non-existent file: "+b)};FS.prototype.PushInode=function(a,b,c){-1!=b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0==this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):(message.Debug("Error in Filesystem: Pushed inode with name = "+c+" has no parent"),message.Abort())};
function Inode(a){this.direntries=new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}
Inode.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=(this.mode&S_IFMT)===S_IFDIR?[...this.direntries]:(this.mode&S_IFMT)===S_IFREG?this.sha256sum:(this.mode&S_IFMT)===S_IFLNK?this.symlink:(this.mode&S_IFMT)===S_IFSOCK?[this.minor,this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};
Inode.prototype.set_state=function(a){this.mode=a[0];if((this.mode&S_IFMT)===S_IFDIR){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else(this.mode&S_IFMT)===S_IFREG?this.sha256sum=a[1]:(this.mode&S_IFMT)===S_IFLNK?this.symlink=a[1]:(this.mode&S_IFMT)===S_IFSOCK&&([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new FSLockRegion;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];
this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&S_IFMT)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};
FS.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new Inode(-1);dbg_assert(d,"Filesystem divert: name ("+b+") not found");dbg_assert(this.IsDirectory(c)||1>=d.nlinks,"Filesystem: can't divert hardlinked file '"+b+"' with nlinks="+d.nlinks);Object.assign(e,d);const g=this.inodes.length;this.inodes.push(e);e.fid=g;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,g);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,g,b));if(this.IsDirectory(c)&&
!this.is_forwarder(d))for(const [f,k]of e.direntries)"."!==f&&".."!==f&&this.IsDirectory(k)&&this.inodes[k].direntries.set("..",g);this.inodedata[g]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return g};FS.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};FS.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new Inode(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};
FS.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=511|S_IFDIR;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|S_IFDIR);c.qid.type=S_IFDIR>>8;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};
FS.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=S_IFREG>>8;c.mode=this.inodes[b].mode&438|S_IFREG;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1};
FS.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=S_IFSOCK>>8;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};
FS.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=S_IFLNK>>8;d.symlink=c;d.mode=S_IFLNK;this.PushInode(d,b,a);return this.inodes.length-1};
FS.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};
FS.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};
FS.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,b);(c.mode&S_IFMT)==S_IFDIR&&this.FillDirectory(a);return!0};FS.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);b.status===STATUS_ON_STORAGE&&this.storage.uncache(b.sha256sum);b.status==STATUS_UNLINKED&&(b.status=STATUS_INVALID,await this.DeleteData(a))};
FS.prototype.Rename=async function(a,b,c,d){if(a==c&&b==d)return 0;var e=this.Search(a,b);if(-1===e)return-ENOENT;var g=this.GetFullPath(a)+"/"+b;if(-1!=this.Search(c,d)){var f=this.Unlink(c,d);if(0>f)return f}var k=this.inodes[e],m=this.inodes[a];f=this.inodes[c];if(this.is_forwarder(m)||this.is_forwarder(f))if(this.is_forwarder(m)&&m.mount_id===f.mount_id){if(a=await this.follow_fs(m).Rename(m.foreign_id,b,f.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return dbg_log("XXX: Attempted to move mountpoint ("+
b+") - skipped",LOG_9P),-EPERM;if(!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return dbg_log("XXX: Attempted to move hardlinked file ("+b+") across filesystems - skipped",LOG_9P),-EPERM;m=this.divert(a,b);const l=this.GetInode(e),n=await this.Read(m,0,l.size);this.is_forwarder(f)?(c=this.follow_fs(f),d=this.IsDirectory(m)?c.CreateDirectory(d,f.foreign_id):c.CreateFile(d,f.foreign_id),c=c.GetInode(d),this.copy_inode(l,c),this.set_forwarder(e,f.mount_id,d)):(this.delete_forwarder(k),this.copy_inode(l,
k),this.link_under_dir(c,e,d));await this.ChangeSize(e,l.size);n&&n.length&&await this.Write(e,0,n.length,n);if(this.IsDirectory(e))for(const p of this.GetChildren(m))if(f=await this.Rename(m,p,e,p),0>f)return f;await this.DeleteData(m);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),k.qid.version++;this.NotifyListeners(e,"rename",{oldpath:g});return 0};
FS.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var g=await this.get_buffer(a);!g||g.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,g=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&g.set(d.subarray(0,c),b);await this.set_data(a,g)}};
FS.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};FS.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===b?-1:b};
FS.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};FS.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=b.CountFreeInodes();return a};FS.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};FS.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};
FS.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;dbg_assert(!1,"Filesystem: Found directory inode whose parent doesn't link to it");return""};
FS.prototype.GetFullPath=function(a){dbg_assert(this.IsDirectory(a),"Filesystem: Cannot get full path of non-directory inode");for(var b="";0!=a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};
FS.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-EPERM;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):(dbg_log("XXX: Attempted to hardlink a file into a child filesystem - skipped",LOG_9P),-EPERM);if(this.is_forwarder(e))return dbg_log("XXX: Attempted to hardlink file across filesystems - skipped",LOG_9P),-EPERM;this.link_under_dir(a,b,c);return 0};
FS.prototype.Unlink=function(a,b){if("."===b||".."===b)return-EPERM;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return dbg_assert(this.is_forwarder(d),"Children of forwarders should be forwarders"),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-ENOTEMPTY;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=STATUS_UNLINKED,this.NotifyListeners(c,"delete"));return 0};
FS.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};
FS.prototype.get_buffer=async function(a){const b=this.inodes[a];dbg_assert(b,`Filesystem get_buffer: idx ${a} does not point to an inode`);return this.inodedata[a]?this.inodedata[a]:b.status===STATUS_ON_STORAGE?(dbg_assert(b.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(b.sha256sum,0,b.size)):null};
FS.prototype.get_data=async function(a,b,c){const d=this.inodes[a];dbg_assert(d,`Filesystem get_data: idx ${a} does not point to an inode`);return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):d.status===STATUS_ON_STORAGE?(dbg_assert(d.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(d.sha256sum,b,c)):null};
FS.prototype.set_data=async function(a,b){this.inodedata[a]=b;this.inodes[a].status===STATUS_ON_STORAGE&&(this.inodes[a].status=STATUS_OK,this.storage.uncache(this.inodes[a].sha256sum))};FS.prototype.GetInode=function(a){dbg_assert(!isNaN(a),"Filesystem GetInode: NaN idx");dbg_assert(0<=a&&a<this.inodes.length,"Filesystem GetInode: out of range idx:"+a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};
FS.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!=c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};
FS.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var g=0;g<b;g++)if(c=d,d=this.Search(c,a[g]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(g).join("/")),-1==d)return g<b-1?{id:-1,parentid:-1,name:a[g],forward_path:e}:{id:-1,parentid:c,name:a[g],forward_path:e};return{id:d,parentid:c,name:a[g],forward_path:e}};
FS.prototype.GetRecursiveList=function(a,b){if(this.is_forwarder(this.inodes[a])){const c=this.follow_fs(this.inodes[a]),d=this.inodes[a].mount_id,e=b.length;c.GetRecursiveList(this.inodes[a].foreign_id,b);for(a=e;a<b.length;a++)b[a].parentid=this.get_forwarder(d,b[a].parentid)}else for(const [c,d]of this.inodes[a].direntries)"."!==c&&".."!==c&&(b.push({parentid:a,name:c}),this.IsDirectory(d)&&this.GetRecursiveList(d,b))};
FS.prototype.RecursiveDelete=function(a){var b=[];a=this.SearchPath(a);if(-1!==a.id)for(this.GetRecursiveList(a.id,b),a=b.length-1;0<=a;a--){const c=this.Unlink(b[a].parentid,b[a].name);dbg_assert(0===c,"Filesystem RecursiveDelete failed at parent="+b[a].parentid+", name='"+b[a].name+"' with error code: "+-c)}};
FS.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!=b.id&&((this.inodes[b.id].mode&S_IFMT)==S_IFREG?(a=this.Unlink(b.parentid,b.name),dbg_assert(0===a,"Filesystem DeleteNode failed with error code: "+-a)):(this.inodes[b.id].mode&S_IFMT)==S_IFDIR&&(this.RecursiveDelete(a),a=this.Unlink(b.parentid,b.name),dbg_assert(0===a,"Filesystem DeleteNode failed with error code: "+-a)))};FS.prototype.NotifyListeners=function(a,b,c){};
FS.prototype.Check=function(){for(var a=1;a<this.inodes.length;a++)if(this.inodes[a].status!=STATUS_INVALID){var b=this.GetInode(a);0>b.nlinks&&message.Debug("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&message.Debug("Error in filesystem: negative parent id "+a);for(const [c,d]of b.direntries){0===c.length&&message.Debug("Error in filesystem: inode with no name and id "+d);for(const e of c)32>e&&
message.Debug("Error in filesystem: Unallowed char in filename")}}}};FS.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+UTF8.UTF8Length(d);a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=marshall.Marshall(["Q","d","b","s"],[b.qid,c+13+8+1+2+UTF8.UTF8Length(d),b.mode>>12,d],a,c)}};
FS.prototype.RoundToDirentry=function(a,b){const c=this.inodedata[a];dbg_assert(c,`FS directory data for dirid=${a} should be generated`);dbg_assert(c.length,"FS directory should have at least an entry");if(b>=c.length)return c.length;for(a=0;;){const d=marshall.Unmarshall(["Q","d"],c,{offset:a})[1];if(d>b)break;a=d}return a};FS.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):(a.mode&S_IFMT)===S_IFDIR};
FS.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;return!0};FS.prototype.GetChildren=function(a){dbg_assert(this.IsDirectory(a),"Filesystem: cannot get children of non-directory inode");a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).GetChildren(a.foreign_id);const b=[];for(const c of a.direntries.keys())"."!==c&&".."!==c&&b.push(c);return b};
FS.prototype.GetParent=function(a){dbg_assert(this.IsDirectory(a),"Filesystem: cannot get parent of non-directory inode");a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);dbg_assert(-1!==b,"Filesystem: should not have invalid parent ids");return this.get_forwarder(a.mount_id,b)};
FS.prototype.PrepareCAPs=function(a){a=this.GetInode(a);if(a.caps)return a.caps.length;a.caps=new Uint8Array(20);a.caps[0]=0;a.caps[1]=0;a.caps[2]=0;a.caps[3]=2;a.caps[4]=255;a.caps[5]=255;a.caps[6]=255;a.caps[7]=255;a.caps[8]=255;a.caps[9]=255;a.caps[10]=255;a.caps[11]=255;a.caps[12]=63;a.caps[13]=0;a.caps[14]=0;a.caps[15]=0;a.caps[16]=63;a.caps[17]=0;a.caps[18]=0;a.caps[19]=0;return a.caps.length};function FSMountInfo(a){this.fs=a;this.backtrack=new Map}
FSMountInfo.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};FSMountInfo.prototype.set_state=function(a){this.fs=a[0];this.backtrack=new Map(a[1])};
FS.prototype.set_forwarder=function(a,b,c){const d=this.inodes[a];dbg_assert(0===d.nlinks,"Filesystem: attempted to convert an inode into forwarder before unlinking the inode");this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.delete(d.foreign_id);d.status=STATUS_FORWARDING;d.mount_id=b;d.foreign_id=c;this.mounts[b].backtrack.set(c,a)};FS.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};
FS.prototype.is_forwarder=function(a){return a.status===STATUS_FORWARDING};FS.prototype.is_a_root=function(a){return 0===this.GetInode(a).fid};FS.prototype.get_forwarder=function(a,b){var c=this.mounts[a];dbg_assert(0<=b,"Filesystem get_forwarder: invalid foreign_id: "+b);dbg_assert(c,"Filesystem get_forwarder: invalid mount number: "+a);c=c.backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};
FS.prototype.delete_forwarder=function(a){dbg_assert(this.is_forwarder(a),"Filesystem delete_forwarder: expected forwarder");a.status=STATUS_INVALID;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};FS.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];dbg_assert(this.is_forwarder(a),"Filesystem follow_fs: inode should be a forwarding inode");dbg_assert(b,"Filesystem follow_fs: inode<id="+a.fid+"> should point to valid mounted FS");return b.fs};
FS.prototype.Mount=function(a,b){dbg_assert(b.qidcounter===this.qidcounter,"Cannot mount filesystem whose qid numbers aren't synchronised with current filesystem.");var c=this.SearchPath(a);if(-1===c.parentid)return dbg_log("Mount failed: parent for path not found: "+a,LOG_9P),-ENOENT;if(-1!==c.id)return dbg_log("Mount failed: file already exists at path: "+a,LOG_9P),-EEXIST;if(c.forward_path)return a=this.inodes[c.parentid],c=this.follow_fs(a).Mount(c.forward_path,b),0>c?c:this.get_forwarder(a.mount_id,
c);a=this.mounts.length;this.mounts.push(new FSMountInfo(b));b=this.create_forwarder(a,0);this.link_under_dir(c.parentid,b,c.name);return b};function FSLockRegion(){this.type=P9_LOCK_TYPE_UNLCK;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}FSLockRegion.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.proc_id;a[4]=this.client_id;return a};
FSLockRegion.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};FSLockRegion.prototype.clone=function(){const a=new FSLockRegion;a.set_state(this.get_state());return a};
FSLockRegion.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.client_id===a.client_id||this.type===P9_LOCK_TYPE_UNLCK||a.type===P9_LOCK_TYPE_UNLCK||this.type!==P9_LOCK_TYPE_WRLCK&&a.type!==P9_LOCK_TYPE_WRLCK||this.start+this.length<=a.start||a.start+a.length<=this.start?!1:!0};FSLockRegion.prototype.is_alike=function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};
FSLockRegion.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};FS.prototype.DescribeLock=function(a,b,c,d,e){dbg_assert(a===P9_LOCK_TYPE_RDLCK||a===P9_LOCK_TYPE_WRLCK||a===P9_LOCK_TYPE_UNLCK,"Filesystem: Invalid lock type: "+a);dbg_assert(0<=b,"Filesystem: Invalid negative lock starting offset: "+b);dbg_assert(0<c,"Filesystem: Invalid non-positive lock length: "+c);const g=new FSLockRegion;g.type=a;g.start=b;g.length=c;g.proc_id=d;g.client_id=e;return g};
FS.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null};
FS.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(b.type!==P9_LOCK_TYPE_UNLCK&&this.GetLock(a,b))return P9_LOCK_BLOCKED;for(c=0;c<d.locks.length;c++){a=d.locks[c];dbg_assert(0<a.length,"Filesystem: Found non-positive lock region length: "+a.length);dbg_assert(a.type===P9_LOCK_TYPE_RDLCK||a.type===P9_LOCK_TYPE_WRLCK,"Filesystem: Found invalid lock type: "+a.type);dbg_assert(!d.locks[c-1]||d.locks[c-1].start<=
a.start,"Filesystem: Locks should be sorted by starting offset");if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){dbg_assert(!a.conflicts_with(b),"Filesytem: Found conflicting lock region, despite already checked for conflicts");continue}var e=b.start+b.length;const g=b.start-a.start,f=a.start+a.length-e;if(0<g&&0<f&&a.type===b.type)return P9_LOCK_SUCCESS;0<g&&(a.length=g);if(0>=g&&0<f)a.start=e,a.length=f;else if(0<f){for(;c<
d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,f,a.proc_id,a.client_id))}else 0>=g&&(d.locks.splice(c,1),c--)}if(b.type!==P9_LOCK_TYPE_UNLCK){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=d.locks[e].length,d.locks.splice(e,1));break}}return P9_LOCK_SUCCESS};
FS.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};FS.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};var VIRTIO_MAGIC_REG=0,VIRTIO_VERSION_REG=4,VIRTIO_DEVICE_REG=8,VIRTIO_VENDOR_REG=12,VIRTIO_HOSTFEATURES_REG=16,VIRTIO_HOSTFEATURESSEL_REG=20,VIRTIO_GUESTFEATURES_REG=32,VIRTIO_GUESTFEATURESSEL_REG=36,VIRTIO_GUEST_PAGE_SIZE_REG=40,VIRTIO_QUEUESEL_REG=48,VIRTIO_QUEUENUMMAX_REG=52,VIRTIO_QUEUENUM_REG=56,VIRTIO_QUEUEALIGN_REG=60,VIRTIO_QUEUEPFN_REG=64,VIRTIO_QUEUENOTIFY_REG=80,VIRTIO_INTERRUPTSTATUS_REG=96,VIRTIO_INTERRUPTACK_REG=100,VIRTIO_STATUS_REG=112,VRING_DESC_F_NEXT=1,VRING_DESC_F_WRITE=2,VRING_DESC_F_INDIRECT=
4;function hex8(a){return h(a)}var message={Debug:function(a){dbg_log([].slice.apply(arguments).join(" "),LOG_9P)},Abort:function(){if(DEBUG)throw Error("message.Abort()");}},LoadBinaryResource;
LoadBinaryResource="undefined"!==typeof XMLHttpRequest?function(a,b,c){var d=new XMLHttpRequest;d.open("GET",a,!0);d.responseType="arraybuffer";d.onreadystatechange=function(){if(4==d.readyState)if(200!=d.status&&0!=d.status)c("Error: Could not load file "+a);else{var e=d.response;e?b(e):c("Error: No data received from: "+a)}};d.send(null)}:function(a,b,c){require("fs").readFile(a,function(d,e){d?c(d):b(e.buffer)})};var marshall={Marshall:function(a,b,c,d){for(var e,g=0,f=0;f<a.length;f++)switch(e=b[f],a[f]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;g+=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;g+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;g+=2;break;case "b":c[d++]=e;g+=1;break;case "s":var k=d,m=0;c[d++]=0;c[d++]=0;g+=2;for(var l of e)UnicodeToUTF8Stream(l.charCodeAt(0)).forEach(function(n){c[d++]=n;g+=1;m++});
c[k+0]=m&255;c[k+1]=m>>8&255;break;case "Q":marshall.Marshall(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;g+=13;break;default:message.Debug("Marshall: Unknown type="+a[f])}return g},Unmarshall:function(a,b,c){let d=c.offset;for(var e=[],g=0;g<a.length;g++)switch(a[g]){case "w":var f=b[d++];f+=b[d++]<<8;f+=b[d++]<<16;f+=b[d++]<<24>>>0;e.push(f);break;case "d":f=b[d++];f+=b[d++]<<8;f+=b[d++]<<16;f+=b[d++]<<24>>>0;d+=4;e.push(f);break;case "h":f=b[d++];e.push(f+(b[d++]<<8));break;case "b":e.push(b[d++]);
break;case "s":f=b[d++];f+=b[d++]<<8;for(var k="",m=new UTF8StreamToUnicode,l=0;l<f;l++){var n=m.Put(b[d++]);-1!=n&&(k+=String.fromCharCode(n))}e.push(k);break;case "Q":c.offset=d;f=marshall.Unmarshall(["b","w","d"],b,c);d=c.offset;e.push({type:f[0],version:f[1],path:f[2]});break;default:message.Debug("Error in Unmarshall: Unknown type="+a[g])}c.offset=d;return e}};var UTF8={};function UTF8StreamToUnicode(){this.stream=new Uint8Array(5);this.ofs=0;this.Put=function(a){this.stream[this.ofs]=a;this.ofs++;switch(this.ofs){case 1:if(128>this.stream[0])return this.ofs=0,this.stream[0];break;case 2:if(192==(this.stream[0]&224)&&128==(this.stream[1]&192))return this.ofs=0,(this.stream[0]&31)<<6|this.stream[1]&63}return-1}}function UnicodeToUTF8Stream(a){if(128>a)return[a];if(2048>a)return[192|a>>6&31,128|a&63]}
UTF8.UTF8Length=function(a){for(var b=0,c=0;c<a.length;c++){var d=a.charCodeAt(c);b+=128>d?1:2}return b};}).call(this);

Binary file not shown.

Binary file not shown.

@ -0,0 +1,405 @@
'use strict';var p,ba="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a};function ca(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var da=ca(this);
function ea(a,b){if(b)a:{var c=da;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];if(!(e in c))break a;c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&ba(c,a,{configurable:!0,writable:!0,value:b})}}ea("globalThis",function(a){return a||da});
ea("Object.fromEntries",function(a){return a?a:function(b){var c={};if(!(Symbol.iterator in b))throw new TypeError(""+b+" is not iterable");b=b[Symbol.iterator].call(b);for(var d=b.next();!d.done;d=b.next()){d=d.value;if(Object(d)!==d)throw new TypeError("iterable for fromEntries should yield objects");c[d[0]]=d[1]}return c}});Object.freeze(["shared","exclusive","unlock"]);
function fa(a,b,c){this.h=a;this.v=c;this.B=[104,111,115,116,57,112];this.F=this.B.length;this.D="9P2000.L";this.j=this.o=8192;this.i=new Uint8Array(2*this.j);this.C=0;this.g=[];this.ab=new ka(b,{name:"virtio-9p",Ia:48,He:4169,Rg:9,Fe:{Vc:43008,Xa:[{Kc:32,me:0}],features:[0,32,29,28],zk:()=>{}},notification:{Vc:43264,Kj:!1,Oh:[d=>{if(0===d){for(;la(this.l);){d=this.l;la(d);var e=d.s.Oa(d.h+4+2*d.j);e=new ma(d,e);d.j=d.j+1&d.o;na(this,e)}d=this.l;e=d.s.Oa(d.h+2)+0&65535;d.s.Ae(d.g+4+8*d.size,e)}}]},
hc:{Vc:42752},Vf:{Vc:42496,td:[{bytes:2,name:"mount tag length",read:()=>this.F,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.B[d]||0,write:()=>{}})))}});this.l=this.ab.Xa[0]}fa.prototype.$=function(){var a=[];a[0]=this.B;a[1]=this.F;a[2]=this.ab;a[3]=this.D;a[4]=this.o;a[5]=this.j;a[6]=this.i;a[7]=this.C;a[8]=this.g.map(function(b){return[b.Z,b.type,b.uid,b.$b]});a[9]=this.h;return a};
fa.prototype.H=function(a){this.B=a[0];this.F=a[1];this.ab.H(a[2]);this.l=this.ab.Xa[0];this.D=a[3];this.o=a[4];this.j=a[5];this.i=a[6];this.C=a[7];this.g=a[8].map(function(b){return{Z:b[0],type:b[1],uid:b[2],$b:b[3]}});this.h.H(a[9])};function u(a,b,c,d){v(["w","b","h"],[d+7,b+1,c],a.i,0);a.C=d+7}function qa(a,b,c){c=v(["w"],[c],a.i,7);u(a,6,b,c)}
function D(a,b){for(var c=a.i.subarray(0,a.C),d=0,e=c.length;e&&b.Nf!==b.Of.length;){var g=b.Of[b.Nf];const f=g.ef+b.Be;g=g.Ne-b.Be;g>e?(g=e,b.Be+=e):(b.Nf++,b.Be=0);ra(b.s,c.subarray(d,d+g),f);d+=g;e-=g}b.qf+=d;c=a.l;d=c.s.Oa(c.g+2)+c.i&c.o;e=b.qf;c.s.Lc(c.g+4+8*d,b.Ph);c.s.Lc(c.g+8+8*d,e);c.i++;a=a.l;0!==a.i&&(b=a.s.Oa(a.g+2)+a.i&65535,a.s.Ae(a.g+2,b),a.i=0,0<(a.ab.h[0]&536870912)?(a.s.Oa(a.h+4+2*a.size),a.ab.Aa(1)):~a.s.Oa(a.h)&1&&a.ab.Aa(1))}
async function na(a,b){var c=new Uint8Array(b.pf);ua(b,c);var d={offset:0},e=E(["w","b","h"],c,d),g=e[0],f=e[1],h=e[2];switch(f){case 8:g=va(a.h);var k=wa(a.h);e=[16914839];e[1]=a.o;e[2]=Math.floor(k/e[1]);e[3]=e[2]-Math.floor(g/e[1]);e[4]=e[2]-Math.floor(g/e[1]);e[5]=xa(a.h);e[6]=za(a.h);e[7]=0;e[8]=256;g=v("wwddddddw".split(""),e,a.i,7);u(a,f,h,g);D(a,b);break;case 112:case 12:e=E(["w","w"],c,d);g=e[0];d=e[1];c=a.g[g].Z;var l=H(a.h,c);k=Aa(a.h,c,d);Ba(a.h,a.g[g].Z,function(){var m=[];m[0]=l.za;
m[1]=this.j-24;v(["Q","w"],m,this.i,7);u(this,f,h,17);D(this,b)}.bind(a));break;case 70:e=E(["w","w","s"],c,d);c=e[0];g=e[1];k=e[2];k=Ca(a.h,a.g[c].Z,a.g[g].Z,k);if(0>k){qa(a,h,-k);D(a,b);break}u(a,f,h,0);D(a,b);break;case 16:e=E(["w","s","s","w"],c,d);g=e[0];k=e[1];var q=e[3];c=Da(a.h,k,a.g[g].Z,e[2]);l=H(a.h,c);l.uid=a.g[g].uid;l.Ga=q;v(["Q"],[l.za],a.i,7);u(a,f,h,13);D(a,b);break;case 18:e=E("wswwww".split(""),c,d);g=e[0];k=e[1];d=e[2];c=e[3];var n=e[4];q=e[5];c=Ea(a.h,k,a.g[g].Z,c,n);l=H(a.h,
c);l.mode=d;l.uid=a.g[g].uid;l.Ga=q;v(["Q"],[l.za],a.i,7);u(a,f,h,13);D(a,b);break;case 22:e=E(["w"],c,d);g=e[0];l=H(a.h,a.g[g].Z);g=v(["s"],[l.te],a.i,7);u(a,f,h,g);D(a,b);break;case 72:e=E(["w","s","w","w"],c,d);g=e[0];k=e[1];d=e[2];q=e[3];c=Fa(a.h,k,a.g[g].Z);l=H(a.h,c);l.mode=d|Ga;l.uid=a.g[g].uid;l.Ga=q;v(["Q"],[l.za],a.i,7);u(a,f,h,13);D(a,b);break;case 14:e=E(["w","s","w","w","w"],c,d);g=e[0];k=e[1];c=e[2];d=e[3];q=e[4];a.v.send("9p-create",[k,a.g[g].Z]);c=Ha(a.h,k,a.g[g].Z);a.g[g].Z=c;a.g[g].type=
1;a.g[g].$b=k;l=H(a.h,c);l.uid=a.g[g].uid;l.Ga=q;l.mode=d;v(["Q","w"],[l.za,a.j-24],a.i,7);u(a,f,h,17);D(a,b);break;case 52:e=E("wbwddws".split(""),c,d);g=e[0];c=e[2];k=0===e[4]?Infinity:e[4];e=Ia(e[1],e[3],k,e[5],e[6]);k=Ja(a.h,a.g[g].Z,e,c);v(["b"],[k],a.i,7);u(a,f,h,1);D(a,b);break;case 54:e=E("wbddws".split(""),c,d);g=e[0];k=0===e[3]?Infinity:e[3];e=Ia(e[1],e[2],k,e[4],e[5]);k=Ka(a.h,a.g[g].Z,e);k||(k=e,k.type=2);g=v(["b","d","d","w","s"],[k.type,k.start,Infinity===k.length?0:k.length,k.h,k.g],
a.i,7);u(a,f,h,g);D(a,b);break;case 24:e=E(["w","d"],c,d);g=e[0];l=H(a.h,a.g[g].Z);if(!l||l.status===La){qa(a,h,2);D(a,b);break}e[0]|=4096;e[0]=e[1];e[1]=l.za;e[2]=l.mode;e[3]=l.uid;e[4]=l.Ga;e[5]=l.Ua;e[6]=l.Oe<<8|l.Pe;e[7]=l.size;e[8]=a.o;e[9]=Math.floor(l.size/512+1);e[10]=l.Oc;e[11]=0;e[12]=l.ic;e[13]=0;e[14]=l.Ed;e[15]=0;e[16]=0;e[17]=0;e[18]=0;e[19]=0;v("dQwwwddddddddddddddd".split(""),e,a.i,7);u(a,f,h,153);D(a,b);break;case 26:e=E("wwwwwddddd".split(""),c,d);g=e[0];l=H(a.h,a.g[g].Z);e[1]&1&&
(l.mode=e[2]);e[1]&2&&(l.uid=e[3]);e[1]&4&&(l.Ga=e[4]);e[1]&16&&(l.Oc=Math.floor((new Date).getTime()/1E3));e[1]&32&&(l.ic=Math.floor((new Date).getTime()/1E3));e[1]&64&&(l.Ed=Math.floor((new Date).getTime()/1E3));e[1]&128&&(l.Oc=e[6]);e[1]&256&&(l.ic=e[8]);e[1]&8&&await Ma(a.h,a.g[g].Z,e[5]);u(a,f,h,0);D(a,b);break;case 50:e=E(["w","d"],c,d);g=e[0];u(a,f,h,0);D(a,b);break;case 40:case 116:e=E(["w","d","w"],c,d);g=e[0];k=e[1];q=e[2];l=H(a.h,a.g[g].Z);if(!l||l.status===La){qa(a,h,2);D(a,b);break}if(2==
a.g[g].type){(void 0).length<k+q&&(q=(void 0).length-k);for(e=0;e<q;e++)a.i[11+e]=(void 0)[k+e];v(["w"],[q],a.i,7);u(a,f,h,4+q)}else Aa(a.h,a.g[g].Z,void 0),e=a.g[g].Z,q=Math.min(q,a.i.length-11),l.size<k+q?q=l.size-k:40==f&&(q=Na(a.h,e,k+q)-k),k>l.size&&(q=0),a.v.send("9p-read-start",[a.g[g].$b]),e=await Oa(a.h,e,k,q),a.v.send("9p-read-end",[a.g[g].$b,q]),e&&a.i.set(e,11),v(["w"],[q],a.i,7),u(a,f,h,4+q);D(a,b);break;case 118:e=E(["w","d","w"],c,d);g=e[0];k=e[1];q=e[2];e=a.g[g].$b;if(2===a.g[g].type){qa(a,
h,95);D(a,b);break}else await Pa(a.h,a.g[g].Z,k,q,c.subarray(d.offset));a.v.send("9p-write-end",[e,q]);v(["w"],[q],a.i,7);u(a,f,h,4);D(a,b);break;case 74:e=E(["w","s","w","s"],c,d);k=await Ra(a.h,a.g[e[0]].Z,e[1],a.g[e[2]].Z,e[3]);if(0>k){qa(a,h,-k);D(a,b);break}u(a,f,h,0);D(a,b);break;case 76:e=E(["w","s","w"],c,d);d=e[0];k=e[1];c=e[2];g=Sa(a.h,a.g[d].Z,k);if(-1==g){qa(a,h,2);D(a,b);break}k=Ta(a.h,a.g[d].Z,k);if(0>k){qa(a,h,-k);D(a,b);break}u(a,f,h,0);D(a,b);break;case 100:g=E(["w","s"],c,d);a.j=
g[0];g=v(["w","s"],[a.j,a.D],a.i,7);u(a,f,h,g);D(a,b);break;case 104:e=E(["w","w","s","s","w"],c,d);g=e[0];a.g[g]={Z:0,type:1,uid:e[4],$b:""};l=H(a.h,a.g[g].Z);v(["Q"],[l.za],a.i,7);u(a,f,h,13);D(a,b);a.v.send("9p-attach");break;case 108:e=E(["h"],c,d);u(a,f,h,0);D(a,b);break;case 110:e=E(["w","w","h"],c,d);g=e[0];q=e[1];n=e[2];if(0==n){a.g[q]={Z:a.g[g].Z,type:1,uid:a.g[g].uid,$b:a.g[g].$b};v(["h"],[0],a.i,7);u(a,f,h,2);D(a,b);break}k=[];for(e=0;e<n;e++)k.push("s");d=E(k,c,d);c=a.g[g].Z;k=9;var t=
0;for(e=0;e<n;e++){c=Sa(a.h,c,d[e]);if(-1==c)break;k+=v(["Q"],[H(a.h,c).za],a.i,k);t++;a.g[q]={Z:c,type:1,uid:a.g[g].uid,$b:d[e]}}v(["h"],[t],a.i,7);u(a,f,h,k-7);D(a,b);break;case 120:e=E(["w"],c,d);a.g[e[0]]&&0<=a.g[e[0]].Z&&(await Ua(a.h,a.g[e[0]].Z),a.g[e[0]].Z=-1,a.g[e[0]].type=-1);u(a,f,h,0);D(a,b);break;case 32:e=E(["w","s","d","w"],c,d);g=e[0];k=e[1];c=e[3];a.g[g].type=2;u(a,f,h,0);D(a,b);break;case 30:e=E(["w","w","s"],c,d),g=e[0],k=e[2],qa(a,h,95),D(a,b)}};function Va(a,b){function c(y){y=y.toString(16);return"#"+"0".repeat(6-y.length)+y}function d(y,B,V,R){y.style.width="";y.style.height="";R&&(y.style.transform="");var aa=y.getBoundingClientRect();R?y.style.transform=(1===B?"":" scaleX("+B+")")+(1===V?"":" scaleY("+V+")"):(0===B%1&&0===V%1?(e.style.imageRendering="crisp-edges",e.style.imageRendering="pixelated",e.style["-ms-interpolation-mode"]="nearest-neighbor"):(e.style.uk="",e.style["-ms-interpolation-mode"]=""),R=window.devicePixelRatio||1,0!==
R%1&&(B/=R,V/=R));1!==B&&(y.style.width=aa.width*B+"px");1!==V&&(y.style.height=aa.height*V+"px")}console.assert(a,"1st argument must be a DOM container");var e=a.getElementsByTagName("canvas")[0],g=e.getContext("2d",{alpha:!1}),f=a.getElementsByTagName("div")[0],h=document.createElement("div"),k,l,q=1,n=1,t=1,m,r=!1,x,w,A,I=!1,O=this;a=new Uint16Array([199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,250,
241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var C=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,
9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),F=[],M,G=0;256>G;G++)M=127<G?a[G-128]:32>G?C[G]:G,F[G]=String.fromCharCode(M);g.imageSmoothingEnabled=!1;h.style.position="absolute";h.style.backgroundColor="#ccc";h.style.width="7px";h.style.display="inline-block";f.style.display="block";e.style.display="none";this.v=b;b.register("screen-set-mode",function(y){this.Df(y)},this);b.register("screen-fill-buffer-end",function(y){this.Kf(y)},
this);b.register("screen-put-char",function(y){this.xf(y[0],y[1],y[2],y[3],y[4])},this);b.register("screen-update-cursor",function(y){this.wd(y[0],y[1])},this);b.register("screen-update-cursor-scanline",function(y){this.xd(y[0],y[1])},this);b.register("screen-clear",function(){this.Sf()},this);b.register("screen-set-size-text",function(y){this.rd(y[0],y[1])},this);b.register("screen-set-size-graphical",function(y){this.qd(y[0],y[1],y[2],y[3])},this);this.hb=function(){this.rd(80,25);this.sb()};this.Xh=
function(){const y=new Image;if(r)y.src=e.toDataURL("image/png");else{const B=[9,16],V=document.createElement("canvas");V.width=w*B[0];V.height=A*B[1];const R=V.getContext("2d");R.imageSmoothingEnabled=!1;R.font=window.getComputedStyle(f).font;R.textBaseline="top";for(let aa=0;aa<w;aa++)for(let ha=0;ha<A;ha++){const ia=3*(ha*w+aa);R.fillStyle=c(x[ia+1]);R.fillRect(aa*B[0],ha*B[1],B[0],B[1]);R.fillStyle=c(x[ia+2]);R.fillText(F[x[ia]],aa*B[0],ha*B[1])}"none"!==h.style.display&&(R.fillStyle=h.style.backgroundColor,
R.fillRect(l*B[0],k*B[1]+parseInt(h.style.marginTop,10)-1,parseInt(h.style.width,10),parseInt(h.style.height,10)));y.src=V.toDataURL("image/png")}try{window.open("").document.write(y.outerHTML)}catch(B){}};this.xf=function(y,B,V,R,aa){y<A&&B<w&&(B=3*(y*w+B),x[B]=V,x[B+1]=R,x[B+2]=aa,m[y]=1)};this.sb=function(){I||requestAnimationFrame(r?X:ja)};var ja=function(){for(var y=0;y<A;y++)m[y]&&(O.g(y),m[y]=0);this.sb()}.bind(this),X=function(){this.v.send("screen-fill-buffer");this.sb()}.bind(this);this.va=
function(){I=!0};this.Df=function(y){(r=y)?(f.style.display="none",e.style.display="block"):(f.style.display="block",e.style.display="none")};this.Sf=function(){g.fillStyle="#000";g.fillRect(0,0,e.width,e.height)};this.rd=function(y,B){if(y!==w||B!==A){m=new Int8Array(B);x=new Int32Array(y*B*3);w=y;for(A=B;f.childNodes.length>B;)f.removeChild(f.firstChild);for(;f.childNodes.length<B;)f.appendChild(document.createElement("div"));for(y=0;y<B;y++)this.g(y);d(f,q,n,!0)}};this.qd=function(y,B){e.style.display=
"block";e.width=y;e.height=B;t=640>=y&&2*y<window.innerWidth&&2*y<window.innerHeight?2:1;d(e,q*t,n*t,!1)};this.Ef=function(y,B){q=y;n=B;d(f,q,n,!0);d(e,q*t,n*t,!1)};this.Ef(q,n);this.xd=function(y,B){y&32?h.style.display="none":(h.style.display="inline",h.style.height=Math.min(15,B-y)+"px",h.style.marginTop=Math.min(15,y)+"px")};this.wd=function(y,B){if(y!==k||B!==l)m[y]=1,m[k]=1,k=y,l=B};this.g=function(y){var B=3*y*w,V;var R=f.childNodes[y];var aa=document.createElement("div");for(var ha=0;ha<w;){var ia=
document.createElement("span");var z=x[B+1];var N=x[B+2];ia.style.backgroundColor=c(z);ia.style.color=c(N);for(V="";ha<w&&x[B+1]===z&&x[B+2]===N;)if(V+=F[x[B]],ha++,B+=3,y===k)if(ha===l)break;else if(ha===l+1){aa.appendChild(h);break}ia.textContent=V;aa.appendChild(ia)}R.parentNode.replaceChild(aa,R)};this.Kf=function(y){y.forEach(B=>{g.putImageData(B.Fb,B.Bf-B.De,B.Cf-B.Ee,B.De,B.Ee,B.gf,B.ff)})};this.hb()};(function(){function a(){for(var n=location.search.substr(1).split("&"),t={},m=0;m<n.length;m++){var r=n[m].split("=");t[r[0]]=decodeURIComponent(r.slice(1).join("="))}return t}function b(n){document.title=n+" - Virtual x86";const t=document.querySelector("meta[name=description]");t&&(t.content="Running "+n)}function c(n){return document.getElementById(n)}function d(){function n(C){c("boot_options").style.display="none";b(C.name);r.filesystem=C.filesystem;C.state&&(c("reset").style.display="none",
r.Wc=C.state);r.ma=C.ma;r.ga=C.ga;r.M=C.M;r.ed=C.ed;r.vb=C.vb;r.Xc=C.Xc;r.Pc=C.Pc;r.hf=C.hf;r.Gb=C.Gb;r.Dd=C.Dd;r.ya=C.state||void 0===r.ya?C.ya:r.ya;r.G=!C.state&&r.G?r.G:C.G;r.ha=!C.state&&r.ha?r.ha:C.ha;r.id=C.id;void 0!==C.oc&&(r.oc=C.oc);var F=parseInt(x.chunk_size,10);0<=F&&(F?(F=Math.min(4194304,Math.max(512,F)),F=1<<Math.ceil(Math.log2(F))):F=void 0,r.M&&(r.M.I=F),r.ga&&(r.ga.I=F));C.da&&(c("description").style.display="block",F=document.createElement("a"),F.href=C.da,F.textContent=C.name,
F.target="_blank",c("description").appendChild(document.createTextNode("Running ")),c("description").appendChild(F));e(r,t)}function t(C){x.c&&setTimeout(function(){Wa(C,x.c+"\n")},25)}if(window.WebAssembly){var m=document.createElement("script");m.src="build/xterm.js";m.async=!0;document.body.appendChild(m);var r={};c("start_emulation").onclick=function(){c("boot_options").style.display="none";k("custom");var C=c("floppy_image").files[0];if(C){var F=C;r.ma={buffer:C}}if(C=c("cd_image").files[0])F=
C,r.ga={buffer:C};if(C=c("hda_image").files[0])F=C,r.M={buffer:C};if(C=c("hdb_image")&&c("hdb_image").files[0])F=C,r.Ke={buffer:C};c("multiboot_image")&&(C=c("multiboot_image").files[0])&&(F=C,r.ed={buffer:C});F&&b(F.name);e(r)};var x=a();m=x.cdn||(l?"images/":"//k.copy.sh/");m=[{id:"archlinux",name:"Arch Linux",G:536870912,ha:8388608,state:{url:m+"arch_state.bin.zst"},filesystem:{Ce:m+"arch/"}},{id:"archlinux-boot",name:"Arch Linux",G:536870912,ha:8388608,filesystem:{Ce:m+"arch/",ih:{url:m+"fs.json"}},
Pc:"rw apm=off vga=0x344 video=vesafb:ypan,vremap:8 root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose mitigations=off audit=0 init_on_free=on tsc=reliable random.trust_cpu=on nowatchdog init=/usr/bin/init-openrc net.ifnames=0 biosdevname=0",hf:!0},{id:"copy/skiffos",name:"SkiffOS",ga:{url:m+"skiffos.iso",size:124672E3,async:!0,I:1048576,aa:!l},G:536870912},{id:"serenity",name:"SerenityOS",M:{url:m+"serenity-v3/.img.zst",size:734003200,async:!0,I:1048576,aa:!0},G:536870912,state:{url:m+
"serenity_state-v4.bin.zst"},da:"https://serenityos.org/",Gb:!0},{id:"serenity-boot",name:"SerenityOS",M:{url:m+"serenity-v3/.img.zst",size:734003200,async:!0,I:1048576,aa:!0},G:536870912,da:"https://serenityos.org/"},{id:"serenity-old",name:"SerenityOS",M:{url:m+"serenity.img",size:918552576,async:!0,I:1048576,aa:!l},G:536870912,state:{url:m+"serenity_state-v2.bin.zst"},da:"https://serenityos.org/"},{id:"serenity-old-boot",name:"SerenityOS",M:{url:m+"serenity.img",size:918552576,async:!0,I:1048576,
aa:!l},G:536870912,da:"https://serenityos.org/"},{id:"redox",name:"Redox",M:{url:m+"redox_demo_i686_2022-11-26_643_harddrive.img",size:536870912,async:!0,I:1048576,aa:!l},G:536870912,state:{url:m+"redox_state.bin.zst"},da:"https://www.redox-os.org/",ya:!0},{id:"redox-boot",name:"Redox",M:{url:m+"redox_demo_i686_2022-11-26_643_harddrive.img",size:536870912,async:!0,I:1048576,aa:!l},G:536870912,da:"https://www.redox-os.org/",ya:!0},{id:"helenos",G:268435456,ga:{url:m+"HelenOS-0.11.2-ia32.iso",size:25765888,
async:!1},name:"HelenOS",da:"http://www.helenos.org/"},{id:"fiwix",G:268435456,M:{url:m+"fiwixos-3.2-i386.img",size:1073741824,async:!0,I:1048576,aa:!l},name:"FiwixOS",da:"https://www.fiwix.org/"},{id:"haiku",G:536870912,M:{url:m+"haiku-v2.img",size:1073741824,async:!0,I:1048576,aa:!l},state:{url:m+"haiku_state-v2.bin.zst"},name:"Haiku",da:"https://www.haiku-os.org/"},{id:"haiku-boot",G:536870912,M:{url:m+"haiku-v2.img",size:1073741824,async:!0,I:1048576,aa:!l},name:"Haiku",da:"https://www.haiku-os.org/"},
{id:"msdos",M:{url:m+"msdos.img",size:8388608,async:!1},oc:306,name:"MS-DOS"},{id:"freedos",ma:{url:m+"freedos722.img",size:737280,async:!1},name:"FreeDOS"},{id:"psychdos",M:{url:m+"psychdos.img",size:549453824,async:!0,I:262144,aa:!l},name:"PsychDOS",da:"https://psychoslinux.gitlab.io/DOS/INDEX.HTM"},{id:"oberon",M:{url:m+"oberon.img",size:25165824,async:!1},name:"Oberon"},{id:"windows1",ma:{url:m+"windows101.img",size:1474560,async:!1},name:"Windows"},{id:"linux26",ga:{url:m+"linux.iso",size:6547456,
async:!1},name:"Linux"},{id:"linux3",ga:{url:m+"linux3.iso",size:8624128,async:!1},name:"Linux"},{id:"linux4",ga:{url:m+"linux4.iso",size:7731200,async:!1},name:"Linux",filesystem:{}},{id:"buildroot",vb:{url:m+"buildroot-bzimage.bin",size:5166352,async:!1},name:"Buildroot Linux",filesystem:{},Pc:"tsc=reliable mitigations=off random.trust_cpu=on"},{id:"nodeos",vb:{url:m+"nodeos-kernel.bin",size:14452E3,async:!1},name:"NodeOS",Pc:"tsc=reliable mitigations=off random.trust_cpu=on"},{id:"dsl",G:268435456,
ga:{url:m+"dsl-4.11.rc2.iso",size:52824064,async:!1},name:"Damn Small Linux",da:"http://www.damnsmalllinux.org/"},{id:"minix",name:"Minix",G:268435456,ga:{url:m+"minix-3.3.0.iso",size:605581312,async:!0,I:1048576,aa:!l},da:"https://www.minix3.org/"},{id:"kolibrios",ma:{url:l?m+"kolibri.img":"//builds.kolibrios.org/eng/data/data/kolibri.img",size:1474560,async:!1},name:"KolibriOS",da:"https://kolibrios.org/en/"},{id:"kolibrios-fallback",ma:{url:m+"kolibri.img",size:1474560,async:!1},name:"KolibriOS"},
{id:"openbsd",M:{url:m+"openbsd.img",size:1073741824,async:!0,I:1048576,aa:!l},state:{url:m+"openbsd_state.bin.zst"},G:268435456,name:"OpenBSD"},{id:"openbsd-boot",M:{url:m+"openbsd.img",size:1073741824,async:!0,I:1048576,aa:!l},G:268435456,name:"OpenBSD"},{id:"netbsd",M:{url:m+"netbsd.img",size:511000064,async:!0,I:1048576,aa:!l},G:268435456,name:"NetBSD"},{id:"solos",ma:{url:m+"os8.img",async:!1,size:1474560},name:"Sol OS",da:"http://oby.ro/os/"},{id:"bootchess",ma:{url:m+"bootchess.img",async:!1,
size:1474560},name:"BootChess",da:"http://www.pouet.net/prod.php?which=64962"},{id:"bootbasic",ma:{url:m+"bootbasic.img",async:!1,size:1474560},name:"bootBASIC",da:"https://github.com/nanochess/bootBASIC"},{id:"sectorlisp",ma:{url:m+"sectorlisp-friendly.bin",async:!1,size:512},name:"SectorLISP",da:"https://justine.lol/sectorlisp2/"},{id:"sectorforth",ma:{url:m+"sectorforth.img",async:!1,size:512},name:"sectorforth",da:"https://github.com/cesarblum/sectorforth"},{id:"floppybird",ma:{url:m+"floppybird.img",
async:!1,size:1474560},name:"Floppy Bird",da:"http://mihail.co/floppybird"},{id:"windows2000",G:536870912,M:{url:m+"windows2k.img",size:2147483648,async:!0,I:262144,aa:!l},name:"Windows 2000",state:{url:m+"windows2k_state-v2.bin.zst"},Gb:!0},{id:"windows2000-boot",G:536870912,M:{url:m+"windows2k.img",size:2147483648,async:!0,I:262144,aa:!l},oc:306,name:"Windows 2000"},{id:"windowsnt4",G:536870912,M:{url:m+"winnt4_noacpi.img",size:523837440,async:!0,I:262144,aa:!l},name:"Windows NT 4.0",Dd:2},{id:"windowsnt3",
G:268435456,M:{url:m+"winnt31.img",size:91226112,async:!0,I:262144,aa:!l},name:"Windows NT 3.1"},{id:"windows98",G:134217728,M:{url:m+"windows98.img",size:314572800,async:!0,I:262144,aa:!l},name:"Windows 98",state:{url:m+"windows98_state.bin.zst"},Gb:!0},{id:"windows98-boot",G:134217728,M:{url:m+"windows98.img",size:314572800,async:!0,I:262144,aa:!l},name:"Windows 98"},{id:"windows95",G:33554432,M:{url:m+"w95.img",size:242049024,async:!0,I:262144,aa:!l},name:"Windows 95",state:{url:m+"windows95_state.bin.zst"}},
{id:"windows95-boot",G:33554432,M:{url:m+"w95.img",size:242049024,async:!0,I:262144,aa:!l},name:"Windows 95"},{id:"windows30",G:67108864,ga:{url:m+"Win30.iso",async:!1},name:"Windows 3.0"},{id:"windows31",G:67108864,M:{url:m+"win31.img",async:!1,size:34463744},name:"Windows 3.1"},{id:"freebsd",G:268435456,M:{url:m+"freebsd.img",size:2147483648,async:!0,I:1048576,aa:!l},state:{url:m+"freebsd_state.bin.zst"},name:"FreeBSD"},{id:"freebsd-boot",G:268435456,M:{url:m+"freebsd.img",size:2147483648,async:!0,
I:1048576,aa:!l},name:"FreeBSD"},{id:"reactos-livecd",G:268435456,M:{url:m+"reactos-livecd-0.4.15-dev-73-g03c09c9-x86-gcc-lin-dbg.iso",size:250609664,async:!0,I:1048576,aa:!l},name:"ReactOS",da:"https://reactos.org/"},{id:"reactos",G:536870912,M:{url:m+"reactos.img",size:524288E3,async:!0,I:1048576,aa:!l},state:{url:m+"reactos_state.bin.zst"},Gb:!0,name:"ReactOS",da:"https://reactos.org/"},{id:"reactos-boot",G:536870912,M:{url:m+"reactos.img",size:524288E3,async:!0,I:1048576,aa:!l},name:"ReactOS",
da:"https://reactos.org/"},{id:"skift",ga:{url:m+"skift-20200910.iso",size:64452608,async:!1},name:"Skift",da:"https://skiftos.org/"},{id:"snowdrop",ma:{url:m+"snowdrop.img",size:1474560,async:!1},name:"Snowdrop",da:"http://www.sebastianmihai.com/snowdrop/"},{id:"openwrt",M:{url:m+"openwrt-18.06.1-x86-legacy-combined-squashfs.img",size:19846474,async:!1},name:"OpenWrt"},{id:"qnx",ma:{url:m+"qnx-demo-network-4.05.img",size:1474560,async:!1},name:"QNX 4.05"},{id:"9front",G:134217728,M:{url:m+"9front-8963.f84cf1e60427675514fb056cc1723e45da01e043.386.iso",
size:477452288,async:!0,I:1048576,aa:!l},state:{url:m+"9front_state-v2.bin.zst"},ya:!0,name:"9front",da:"https://9front.org/"},{id:"9front-boot",G:134217728,M:{url:m+"9front-8963.f84cf1e60427675514fb056cc1723e45da01e043.386.iso",size:477452288,async:!0,I:1048576,aa:!l},ya:!0,name:"9front",da:"https://9front.org/"},{id:"mobius",ma:{url:m+"mobius-fd-release5.img",size:1474560,async:!1},name:"Mobius"},{id:"android",G:536870912,ga:{url:m+"android-x86-1.6-r2.iso",size:54661120,async:!0,I:1048576,aa:!l},
name:"Android"},{id:"android4",G:536870912,ga:{url:m+"android_x86_nonsse3_4.4r1_20140904.iso",size:247463936,async:!0,I:1048576,aa:!l},name:"Android"},{id:"tinycore",G:268435456,M:{url:m+"TinyCore-11.0.iso",async:!1},name:"Tinycore",da:"http://www.tinycorelinux.net/"},{id:"freenos",G:268435456,ga:{url:m+"FreeNOS-1.0.3.iso",async:!1,size:11014144},name:"FreeNOS",ya:!0,da:"http://www.freenos.org/"}];var w=x.profile;if(!w){var A=document.createElement("link");A.rel="prefetch";A.href="build/v86.wasm";
document.head.appendChild(A)}x.use_bochs_bios&&(r.Oj=!0);A=parseInt(x.m,10);0<A&&(r.G=1048576*Math.max(16,A));A=parseInt(x.vram,10);0<A&&(r.ha=1048576*A);r.mg=x.networking_proxy;r.audio="0"!==x.audio;r.ya=x.acpi;for(A=0;A<m.length;A++){var I=m[A];if(w===I.id){n(I);return}var O=c("start_"+I.id);O&&(O.onclick=function(C,F,M){M.preventDefault();k(C.id);F.blur();n(C)}.bind(this,I,O))}if("custom"===w){if(x["hda.url"]&&(r.M={size:parseInt(x["hda.size"],10)||void 0,url:x["hda.url"],async:!0}),x["cdrom.url"]&&
(r.ga={size:parseInt(x["cdrom.size"],10)||void 0,url:x["cdrom.url"],async:!0}),x["fda.url"]&&(r.ma={size:parseInt(x["fda.size"],10)||void 0,url:x["fda.url"],async:!1}),r.ma||r.ga||r.M)c("boot_options").style.display="none",e(r,t)}else if(/^[a-zA-Z0-9\-_]+\/[a-zA-Z0-9\-_]+$/g.test(w)){const C="https://v86-user-images.b-cdn.net/"+w;fetch(C+"/profile.json").then(F=>F.json()).then(F=>{function M(G){return G&&{url:C+"/"+G.url,async:G.async,size:G.size}}n({id:F.id,name:F.name,G:F.memory_size,ha:F.vga_memory_size,
ya:F.acpi,oc:F.boot_order,M:M(F.hda),ga:M(F.cdrom),ma:M(F.fda),ed:M(F.multiboot),vb:M(F.bzimage),Xc:M(F.initrd)})}).catch(()=>alert("Profile not found: "+w))}}else alert("Your browser is not supported because it doesn't support WebAssembly")}function e(n,t){var m=n.G;m||(m=1048576*parseInt(c("memory_size").value,10),m||(alert("Invalid memory size - reset to 128MB"),m=134217728));var r=n.ha;r||(r=1048576*parseInt(c("video_memory_size").value,10),r||(alert("Invalid video memory size - reset to 8MB"),
r=8388608));if(!n.ma){var x=c("floppy_image").files[0];x&&(n.ma={buffer:x})}!n.vb&&(x=c("bzimage").files[0])&&(n.vb={buffer:x});!n.Xc&&(x=c("initrd").files[0])&&(n.Xc={buffer:x});x=void 0===n.mg?c("networking_proxy").value:n.mg;const w=void 0===n.audio?c("disable_audio").checked:!n.audio,A=void 0===n.ya?c("enable_acpi").checked:n.ya;if(n.Oj)var I="bochs-bios.bin",O="bochs-vgabios.bin";else I="seabios.bin",O="vgabios.bin";if(!n.Wc){var C={url:"bios/"+I};var F={url:"bios/"+O}}var M=new Xa({memory_size:m,
vga_memory_size:r,screen_container:c("screen_container"),serial_container_xtermjs:c("terminal"),boot_order:n.oc||parseInt(c("boot_order").value,16)||0,network_relay_url:l?"ws://localhost:8080/":x,bios:C,vga_bios:F,fda:n.ma,hda:n.M,hdb:n.Ke,cdrom:n.ga,multiboot:n.ed,bzimage:n.vb,initrd:n.Xc,cmdline:n.Pc,bzimage_initrd_from_filesystem:n.hf,acpi:A,initial_state:n.Wc,filesystem:n.filesystem||{},disable_speaker:w,mac_address_translation:n.Gb,cpuid_level:n.Dd,autostart:!0});J(M,"emulator-ready",function(){if(M.g.s.xa.exports.profiler_is_enabled()){var G=
document.createElement("pre");document.body.appendChild(G);setInterval(function(){if(M.Zc()){var ja=Ya.Lj(M.g.s);G.textContent=ja}},1E3)}"dsl"===n.id||"helenos"===n.id?setTimeout(()=>{Wa(M,"\n")},3E3):("android"===n.id||"android4"===n.id)&&setTimeout(()=>{Za(M,[57424,57552]);Wa(M,"\n")},3E3);g(n,M);t&&t(M)});J(M,"download-progress",function(G){var ja=c("loading");ja.style.display="block";if(G.he.endsWith(".wasm")){var X=G.he.split("/");ja.textContent="Fetching "+X[X.length-1]+" ..."}else if(G.ge===
G.fe-1&&G.loaded>=G.total-2048)ja.textContent="Done downloading. Starting now ...";else{X="Downloading images ";"number"===typeof G.ge&&G.fe&&(X+="["+(G.ge+1)+"/"+G.fe+"] ");if(G.total&&"number"===typeof G.loaded){G=Math.floor(G.loaded/G.total*100);G=Math.min(100,Math.max(0,G));var y=Math.floor(G/2);X=X+(G+"% [")+"#".repeat(y);X+=" ".repeat(50-y)+"]"}else X+=".".repeat(q++%50);ja.textContent=X}});J(M,"download-error",function(G){var ja=c("loading");ja.style.display="block";ja.textContent="Loading "+
G.he+" failed. Check your connection and reload the page to try again."})}function g(n,t){function m(){var z=Date.now(),N=t.g?t.g.s.Th[0]>>>0:0;N<O&&(O-=4294967296);var P=N-O;O=N;M+=P;if(N=z-A)I+=N,A=z,c("speed").textContent=(P/1E3/N).toFixed(1),c("avg_speed").textContent=(M/1E3/I).toFixed(1),z=c("running_time"),P=I/1E3|0,z.textContent=60>P?P+"s":3600>P?(P/60|0)+"m "+$a(P%60,2)+"s":(P/3600|0)+"h "+$a((P/60|0)%60,2)+"m "+$a(P%60,2)+"s"}function r(z,N){var P=c("get_"+N+"_image");!z||104857600<z.size?
P.style.display="none":P.onclick=function(){var Y=t.ac[N];let oa=Y.file&&Y.file.name||n.id+("cdrom"===N?".iso":".img");Y.fg?(Y=Y.fg(oa),ab(Y,oa)):Y.pb(function(Qa){Qa?bb(Qa,oa):alert("The file could not be loaded. Maybe it's too big?")});P.blur()}}function x(z){z.ctrlKey?window.onbeforeunload=function(){window.onbeforeunload=null;return"CTRL-W cannot be sent to the emulator."}:window.onbeforeunload=null}c("boot_options").style.display="none";c("loading").style.display="none";c("runtime_options").style.display=
"block";c("runtime_infos").style.display="block";c("screen_container").style.display="block";n.filesystem?f(t):J(t,"9p-attach",function(){f(t)});c("run").onclick=function(){t.Zc()?(c("run").value="Run",t.stop()):(c("run").value="Pause",t.Ze());c("run").blur()};c("exit").onclick=function(){t.stop();location.href=location.pathname};c("lock_mouse").onclick=function(){if(!w)c("toggle_mouse").onclick();cb();c("lock_mouse").blur()};var w=!0;c("toggle_mouse").onclick=function(){w=!w;t.l&&(t.l.Ie=w);c("toggle_mouse").value=
(w?"Dis":"En")+"able mouse";c("toggle_mouse").blur()};var A=0,I=0,O=0,C=null,F=!1,M=0;J(t,"emulator-started",function(){A=Date.now();C=setInterval(m,1E3)});J(t,"emulator-stopped",function(){m();null!==C&&clearInterval(C)});var G=0,ja=0,X=[];J(t,"9p-read-start",function(z){z=z[0];X.push(z);c("info_filesystem").style.display="block";c("info_filesystem_status").textContent="Loading ...";c("info_filesystem_last_file").textContent=z});J(t,"9p-read-end",function(z){G+=z[1];c("info_filesystem_bytes_read").textContent=
G;const N=z[0];X=X.filter(P=>P!==N);X[0]?c("info_filesystem_last_file").textContent=X[0]:c("info_filesystem_status").textContent="Idle"});J(t,"9p-write-end",function(z){ja+=z[1];c("info_filesystem_bytes_written").textContent=ja;X[0]||(c("info_filesystem_last_file").textContent=z[0])});var y=0,B=0,V=0,R=0;J(t,"ide-read-start",function(){c("info_storage").style.display="block";c("info_storage_status").textContent="Loading ..."});J(t,"ide-read-end",function(z){y+=z[1];B+=z[2];c("info_storage_status").textContent=
"Idle";c("info_storage_bytes_read").textContent=y;c("info_storage_sectors_read").textContent=B});J(t,"ide-write-end",function(z){V+=z[1];R+=z[2];c("info_storage_bytes_written").textContent=V;c("info_storage_sectors_written").textContent=R});var aa=0,ha=0;J(t,"eth-receive-end",function(z){ha+=z[0];c("info_network").style.display="block";c("info_network_bytes_received").textContent=ha});J(t,"eth-transmit-end",function(z){aa+=z[0];c("info_network").style.display="block";c("info_network_bytes_transmitted").textContent=
aa});J(t,"mouse-enable",function(z){F=z;c("info_mouse_enabled").textContent=z?"Yes":"No"});J(t,"screen-set-mode",function(z){z?c("info_vga_mode").textContent="Graphical":(c("info_vga_mode").textContent="Text",c("info_res").textContent="-",c("info_bpp").textContent="-")});J(t,"screen-set-size-graphical",function(z){c("info_res").textContent=z[0]+"x"+z[1];c("info_bpp").textContent=z[4]});c("reset").onclick=function(){t.zf();c("reset").blur()};r(n.M,"hda");r(n.Ke,"hdb");r(n.ma,"fda");r(n.Zf,"fdb");r(n.ga,
"cdrom");c("memory_dump").onclick=function(){const z=t.g.s.Na;bb(new Uint8Array(z.buffer,z.byteOffset,z.length),"v86memory.bin");c("memory_dump").blur()};c("capture_network_traffic").onclick=function(){function z(P,Y){var oa=N,Qa=oa.push,Le=performance.now()/1E3;const fc=[];let pa=0;for(;pa+15<Y.length;pa+=16){var sa=$a(pa.toString(16).toUpperCase(),5)+" ";for(var ta=0;16>ta;ta++)sa+=$a(Y[pa+ta].toString(16).toUpperCase(),2)+" ";sa+=" ";for(ta=0;16>ta;ta++){var ya=Y[pa+ta];sa+=33<=ya&&34!==ya&&
92!==ya&&126>=ya?String.fromCharCode(ya):"."}fc.push(sa)}for(sa=$a(pa.toString(16).toUpperCase(),5)+" ";pa<Y.length;pa++)sa+=$a(Y[pa].toString(16).toUpperCase(),2)+" ";ta=pa&15;sa+=" ".repeat(16-ta);sa+=" ";for(ya=0;ya<ta;ya++){const fb=Y[pa+ya];sa+=33<=fb&&34!==fb&&92!==fb&&126>=fb?String.fromCharCode(fb):"."}fc.push(sa);Qa.call(oa,{direction:P,time:Le,Rh:"\n"+fc.join("\n")+"\n"});c("capture_network_traffic").value=N.length+" packets"}this.value="0 packets";let N=[];t.Gd.register("net0-receive",
z.bind(this,"I"));J(t,"net0-send",z.bind(this,"O"));this.onclick=function(){const P=N.map(({direction:Y,time:oa,Rh:Qa})=>Y+" "+oa.toFixed(6)+Qa+"\n").join("");bb(P,"traffic.hex");N=[];this.value="0 packets"}};c("save_state").onclick=async function(){const z=await t.se();bb(z,"v86state.bin");c("save_state").blur()};c("load_state").onclick=function(){c("load_state_input").click();c("load_state").blur()};c("load_state_input").onchange=async function(){var z=this.files[0];if(z){var N=t.Zc();N&&await t.stop();
var P=new FileReader;P.onload=async function(Y){try{await t.Nd(Y.target.result)}catch(oa){throw alert("Something bad happened while restoring the state:\n"+oa+"\n\nNote that the current configuration must be the same as the original"),oa;}N&&t.Ze()};P.readAsArrayBuffer(z);this.value=""}};c("ctrlaltdel").onclick=function(){Za(t,[29,56,83,157,184,211]);c("ctrlaltdel").blur()};c("alttab").onclick=function(){Za(t,[56,15]);setTimeout(function(){Za(t,[184,143])},100);c("alttab").blur()};c("scale").onchange=
function(){var z=parseFloat(this.value);(z||0<z)&&t.h&&t.h.Ef(z,z)};c("fullscreen").onclick=function(){if(t.h){var z=document.getElementById("screen_container");if(z){var N=z.requestFullScreen||z.webkitRequestFullscreen||z.mozRequestFullScreen||z.msRequestFullScreen;N&&(N.call(z),(z=document.getElementsByClassName("phone_keyboard")[0])&&z.focus());try{navigator.keyboard.lock()}catch(P){}cb()}}};c("screen_container").onclick=function(){if(w&&F)cb(),c("lock_mouse").blur();else if(window.getSelection().isCollapsed){let z=
document.getElementsByClassName("phone_keyboard")[0];z.style.top=document.body.scrollTop+100+"px";z.style.left=document.body.scrollLeft+100+"px";z.focus()}};const ia=document.getElementsByClassName("phone_keyboard")[0];ia.setAttribute("autocorrect","off");ia.setAttribute("autocapitalize","off");ia.setAttribute("spellcheck","false");ia.tabIndex=0;c("screen_container").addEventListener("mousedown",()=>{ia.focus()},!1);c("take_screenshot").onclick=function(){t.h&&t.h.Xh();c("take_screenshot").blur()};
if(t.j){let z=!1;c("mute").onclick=function(){z?(t.j.Qe.af(1,void 0),z=!1,c("mute").value="Mute"):(t.j.Qe.af(0,void 0),z=!0,c("mute").value="Unmute");c("mute").blur()}}else c("mute").remove();window.addEventListener("keydown",x,!1);window.addEventListener("keyup",x,!1);window.addEventListener("blur",x,!1)}function f(n){c("filesystem_panel").style.display="block";c("filesystem_send_file").onchange=function(){Array.prototype.forEach.call(this.files,function(t){var m=new db(t);m.onload=function(){m.pb(async function(r){await n.qh("/"+
t.name,new Uint8Array(r))})};m.load()},this);this.value="";this.blur()};c("filesystem_get_file").onkeypress=async function(t){if(13===t.which){this.disabled=!0;try{var m=await n.re(this.value)}catch(r){console.log(r)}this.disabled=!1;m?(t=this.value.replace(/\/$/,"").split("/"),t=t[t.length-1]||"root",bb(m,t),this.value=""):alert("Can't read file")}}}function h(){location.reload()}function k(n){window.history.pushState&&window.history.pushState({profile:n},"","?profile="+n)}var l=!location.hostname.endsWith("copy.sh"),
q=0;window.addEventListener("load",d,!1);window.addEventListener("load",function(){setTimeout(function(){window.addEventListener("popstate",h)},0)});"complete"===document.readyState&&d()})();function eb(a){this.ports=[];this.s=a;for(var b=0;65536>b;b++)this.ports[b]=gb(this);var c=a.G[0];for(b=0;b<<17<c;b++)a.i[b]=a.l[b]=void 0,a.pa[b]=a.j[b]=void 0;hb(this,c,4294967296-c,function(){return 255},function(){},function(){return-1},function(){})}function gb(a){return{od:a.Eh,Oa:a.Ch,qe:a.Dh,df:a.kf,Ae:a.kf,Lc:a.kf,oa:void 0}}p=eb.prototype;p.Eh=function(){return 255};p.Ch=function(){return 65535};p.Dh=function(){return-1};p.kf=function(){};
function K(a,b,c,d,e,g){d&&(a.ports[b].od=d);e&&(a.ports[b].Oa=e);g&&(a.ports[b].qe=g);a.ports[b].oa=c}function L(a,b,c,d,e,g){d&&(a.ports[b].df=d);e&&(a.ports[b].Ae=e);g&&(a.ports[b].Lc=g);a.ports[b].oa=c}
p.pd=function(a,b,c,d,e,g){function f(){return c.call(this)|d.call(this)<<8}function h(){return e.call(this)|g.call(this)<<8}function k(){return c.call(this)|d.call(this)<<8|e.call(this)<<16|g.call(this)<<24}e&&g?(K(this,a,b,c,f,k),K(this,a+1,b,d),K(this,a+2,b,e,h),K(this,a+3,b,g)):(K(this,a,b,c,f),K(this,a+1,b,d))};
p.Lb=function(a,b,c,d,e,g){function f(l){c.call(this,l&255);d.call(this,l>>8&255)}function h(l){e.call(this,l&255);g.call(this,l>>8&255)}function k(l){c.call(this,l&255);d.call(this,l>>8&255);e.call(this,l>>16&255);g.call(this,l>>>24)}e&&g?(L(this,a,b,c,f,k),L(this,a+1,b,d),L(this,a+2,b,e,h),L(this,a+3,b,g)):(L(this,a,b,c,f),L(this,a+1,b,d))};p.Zh=function(a){var b=this.s.i[a>>>17];return b(a)|b(a+1)<<8|b(a+2)<<16|b(a+3)<<24};
p.$h=function(a,b){var c=this.s.l[a>>>17];c(a,b&255);c(a+1,b>>8&255);c(a+2,b>>16&255);c(a+3,b>>>24)};function hb(a,b,c,d,e,g,f){g||(g=a.Zh.bind(a));f||(f=a.$h.bind(a));for(b>>>=17;0<c;b++)a.s.i[b]=d,a.s.l[b]=e,a.s.pa[b]=g,a.s.j[b]=f,c-=131072};function ib(a,b){this.i=this.g=!1;this.j=0;this.h=null;this.s=new jb(a,b,()=>{this.C&&kb(this,0)});this.v=a;a.register("cpu-init",this.hb,this);a.register("cpu-run",this.Ze,this);a.register("cpu-stop",this.stop,this);a.register("cpu-restart",this.zf,this);this.l()}p=ib.prototype;p.Ze=function(){this.i=!1;this.g||(this.g=!0,this.v.send("emulator-started"));kb(this,0)};
function lb(a){if(a.i||!a.g)a.i=a.g=!1,a.v.send("emulator-stopped");else{a.C=!1;a:{var b=a.s;if(b.h[0]){var c=mb(b);if(b.h[0]){b=c;break a}}let d=c=nb();for(;1>d-c;){b.Tj();d=nb();const e=ob(b,d);pb(b);if(b.h[0]){b=e;break a}}b=0}kb(a,b)}}function kb(a,b){const c=++a.j;a.C=!0;a.B(b,c)}p.stop=function(){this.g&&(this.i=!0)};p.va=function(){this.o()};p.zf=function(){this.s.Ra();qb(this.s)};p.hb=function(a){this.s.hb(a,this.v);this.v.send("emulator-ready")};
if("undefined"!==typeof process)ib.prototype.B=function(a,b){1>a?global.setImmediate(c=>{c===this.j&&lb(this)},b):setTimeout(c=>{c===this.j&&lb(this)},a,b)},ib.prototype.l=function(){},ib.prototype.o=function(){};else if("undefined"!==typeof Worker){function a(){globalThis.onmessage=function(b){const c=b.data.t;1>c?postMessage(b.data.Sg):setTimeout(()=>postMessage(b.data.Sg),c)}}ib.prototype.l=function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.h=
new Worker(b);this.h.onmessage=c=>{c.data===this.j&&lb(this)};URL.revokeObjectURL(b)};ib.prototype.B=function(b,c){this.h.postMessage({t:b,Sg:c})};ib.prototype.o=function(){this.h.terminate();this.h=null}}else ib.prototype.B=function(a){setTimeout(()=>{lb(this)},a)},ib.prototype.l=function(){},ib.prototype.o=function(){};ib.prototype.se=function(){return this.s.se()};ib.prototype.Nd=function(a){return this.s.Nd(a)};
if("object"===typeof performance&&performance.now)var nb=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");nb=a.now.bind(a)}else"object"===typeof process&&process.hrtime?nb=function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:nb=Date.now;var db,rb,sb,tb,ub,vb,wb;function xb(a,b){return(a||0===a?a+"":"").padEnd(b," ")}function $a(a,b){return(a||0===a?a+"":"").padStart(b,"0")}function Q(a,b,c,d){return new Proxy({},{get:function(e,g){e=new a(b.buffer,c,d);g=e[g];return"function"===typeof g?g.bind(e):g},set:function(e,g,f){(new a(b.buffer,c,d))[g]=f;return!0}})}function yb(a,b){return"0x"+$a((a?a.toString(16):"").toUpperCase(),b||1)}
if("undefined"!==typeof crypto&&crypto.getRandomValues){let a=new Int32Array(1);var zb=function(){crypto.getRandomValues(a);return a[0]}}else if("undefined"!==typeof require){const a=require("crypto");zb=function(){return a.Ck(4).readInt32LE(0)}}
(function(){if("function"===typeof Math.clz32)rb=function(d){return 31-Math.clz32(d)},sb=function(d){return 31-Math.clz32(d)};else{for(var a=new Int8Array(256),b=0,c=-2;256>b;b++)b&b-1||c++,a[b]=c;rb=function(d){return a[d]};sb=function(d){d>>>=0;var e=d>>>16;if(e){var g=e>>>8;return g?24+a[g]:16+a[e]}return(g=d>>>8)?8+a[g]:a[d]}}})();
function Ab(a){var b=new Uint8Array(a),c,d;this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-1;this.length--;return e}return-1};this.clear=function(){this.length=d=c=0};this.clear()}function Bb(){this.size=65536;this.data=new Float32Array(65536);this.length=this.end=this.start=0}
Bb.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};Bb.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;return a}};
function Cb(a,b){var c=new Float32Array(b);b>a.length&&(b=a.length);var d=a.start+b,e=a.data.subarray(a.start,d);c.set(e);d>=a.size&&(d-=a.size,c.set(a.data.subarray(0,d),e.length));a.start=d;a.length-=b;return c}Bb.prototype.clear=function(){this.length=this.end=this.start=0};function bb(a,b){a instanceof Array||(a=[a]);ab(new Blob(a),b)}
function ab(a,b){var c=document.createElement("a");c.download=b;c.href=window.URL.createObjectURL(a);c.dataset.downloadurl=["application/octet-stream",c.download,c.href].join(":");document.createEvent?(a=document.createEvent("MouseEvent"),a.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(a)):c.click();window.URL.revokeObjectURL(c.href)}function Db(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof ArrayBuffer&&(this.view=new Uint8Array(a))}
Db.prototype.set=function(a,b){const c=a>>3;a=1<<(a&7);this.view[c]=b?this.view[c]|a:this.view[c]&~a};Db.prototype.get=function(a){return this.view[a>>3]>>(a&7)&1};Db.prototype.pb=function(){return this.view.buffer};var Gb="undefined"===typeof XMLHttpRequest?Eb:Fb;
function Fb(a,b,c){function d(){const k=c||0;setTimeout(()=>{Fb(a,b,k+1)},1E3*([1,1,2,3,5,8,13,21][k]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.zd?"json":"arraybuffer";if(b.headers)for(var g=Object.keys(b.headers),f=0;f<g.length;f++){var h=g[f];e.setRequestHeader(h,b.headers[h])}b.Ld&&(g=b.Ld.start,e.setRequestHeader("Range","bytes="+g+"-"+(g+b.Ld.length-1)),e.onreadystatechange=function(){200===e.status&&e.abort()});e.onload=function(){4===e.readyState&&(200!==
e.status&&206!==e.status?(console.error("Loading the image "+a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d()):e.response&&b.done&&b.done(e.response,e))};e.onerror=function(k){console.error("Loading the image "+a+" failed",k);d()};b.progress&&(e.onprogress=function(k){b.progress(k)});e.send(null)}
function Eb(a,b){let c=require("fs");b.Ld?c.open(a,"r",(d,e)=>{if(d)throw d;d=b.Ld.length;var g=Buffer.allocUnsafe(d);c.read(e,g,0,d,b.Ld.start,f=>{if(f)throw f;b.done&&b.done(new Uint8Array(g));c.close(e,h=>{if(h)throw h;})})}):c.readFile(a,{encoding:b.zd?"utf-8":null},function(d,e){d?console.log("Could not read file:",a,d):(d=e,b.zd?d=JSON.parse(d):d=(new Uint8Array(d)).buffer,b.done(d))})};(function(){function a(f){this.buffer=f;this.byteLength=f.byteLength;this.onload=void 0}function b(f,h,k){this.filename=f;this.byteLength=h;this.g=new Map;this.i=new Set;this.I=k;this.B=!!k;this.onload=void 0}function c(f,h,k,l,q){const n=f.match(/\.[^\.]+(\.zst)?$/);this.j=n?n[0]:"";this.h=f.substring(0,f.length-this.j.length);this.D=this.j.endsWith(".zst");this.h.endsWith("/")||(this.h+="-");this.g=new Map;this.i=new Set;this.byteLength=h;this.I=k;this.F=!!l;this.C=q;this.B=!!k;this.onload=void 0}
function d(f){this.file=f;this.byteLength=f.size;1073741824<f.size&&console.warn("SyncFileBuffer: Allocating buffer of "+(f.size>>20)+" MB ...");this.buffer=new ArrayBuffer(f.size);this.onload=void 0}function e(f){this.file=f;this.byteLength=f.size;this.g=new Map;this.i=new Set;this.onload=void 0}tb=a;ub=b;vb=c;wb=e;db=d;a.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};a.prototype.get=function(f,h,k){k(new Uint8Array(this.buffer,f,h))};a.prototype.set=function(f,h,k){(new Uint8Array(this.buffer,
f,h.byteLength)).set(h);k()};a.prototype.pb=function(f){f(this.buffer)};a.prototype.$=function(){const f=[];f[0]=this.byteLength;f[1]=new Uint8Array(this.buffer);return f};a.prototype.H=function(f){this.byteLength=f[0];this.buffer=f[1].slice().buffer};b.prototype.load=function(){void 0!==this.byteLength?this.onload&&this.onload(Object.create(null)):g(this.filename,(f,h)=>{if(f)throw Error("Cannot use: "+this.filename+". "+f);this.byteLength=h;this.onload&&this.onload(Object.create(null))})};b.prototype.h=
function(f,h){var k=h/256;f/=256;for(var l=0;l<k;l++)if(!this.g.get(f+l))return;if(1===k)return this.g.get(f);h=new Uint8Array(h);for(l=0;l<k;l++)h.set(this.g.get(f+l),256*l);return h};b.prototype.get=function(f,h,k){var l=this.h(f,h);if(l)k(l);else{var q=f,n=h;this.I&&(q=f-f%this.I,n=Math.ceil((f-q+h)/this.I)*this.I);Gb(this.filename,{done:function(t){t=new Uint8Array(t);this.j(q,n,t);q===f&&n===h?k(t):k(t.subarray(f-q,f-q+h))}.bind(this),Ld:{start:q,length:n}})}};b.prototype.set=function(f,h,k){f/=
256;for(var l=h.length/256,q=0;q<l;q++){var n=this.g.get(f+q);void 0===n?this.g.set(f+q,h.slice(256*q,256*(q+1))):n.set(h.subarray(256*q,256*(q+1)));this.i.add(f+q)}k()};b.prototype.j=function(f,h,k){f/=256;h/=256;for(var l=0;l<h;l++){const q=this.g.get(f+l);q?k.set(q,256*l):this.B&&this.g.set(f+l,k.slice(256*l,256*(l+1)))}};b.prototype.pb=function(f){f()};b.prototype.$=function(){const f=[],h=[];for(let [k,l]of this.g)this.i.has(k)&&h.push([k,l]);f[0]=h;return f};b.prototype.H=function(f){f=f[0];
this.g.clear();this.i.clear();for(let [h,k]of f)this.g.set(h,k),this.i.add(h)};c.prototype.load=function(){this.onload&&this.onload(Object.create(null))};c.prototype.get=function(f,h,k){var l=this.l(f,h);if(l)k(l);else if(this.I){const n=Math.floor(f/this.I),t=f-n*this.I,m=Math.ceil((t+h)/this.I),r=new Uint8Array(m*this.I);let x=0;for(let w=0;w<m;w++){var q=(n+w)*this.I;l=this.F?this.h+(n+w+"").padStart(8,"0")+this.j:this.h+q+"-"+(q+this.I)+this.j;(q=this.l(q,this.I))?(r.set(q,w*this.I),x++,x===m&&
k(r.subarray(t,t+h))):Gb(l,{done:async function(A){A=new Uint8Array(A);this.D&&(A=await this.C(this.I,A),A=new Uint8Array(A));r.set(A,w*this.I);this.o((n+w)*this.I,this.I|0,A);x++;x===m&&k(r.subarray(t,t+h))}.bind(this)})}}else Gb(this.h+f+"-"+(f+h)+this.j,{done:function(n){n=new Uint8Array(n);this.o(f,h,n);k(n)}.bind(this)})};c.prototype.l=b.prototype.h;c.prototype.set=b.prototype.set;c.prototype.o=b.prototype.j;c.prototype.$=b.prototype.$;c.prototype.H=b.prototype.H;d.prototype.load=function(){this.g(0)};
d.prototype.g=function(f){var h=new FileReader;h.onload=function(k){k=new Uint8Array(k.target.result);(new Uint8Array(this.buffer,f)).set(k);this.g(f+4194304)}.bind(this);f<this.byteLength?h.readAsArrayBuffer(this.file.slice(f,Math.min(f+4194304,this.byteLength))):(this.file=void 0,this.onload&&this.onload({buffer:this.buffer}))};d.prototype.get=a.prototype.get;d.prototype.set=a.prototype.set;d.prototype.pb=a.prototype.pb;d.prototype.$=a.prototype.$;d.prototype.H=a.prototype.H;e.prototype.load=function(){this.onload&&
this.onload(Object.create(null))};e.prototype.get=function(f,h,k){var l=this.h(f,h);l?k(l):(l=new FileReader,l.onload=function(q){q=new Uint8Array(q.target.result);this.j(f,h,q);k(q)}.bind(this),l.readAsArrayBuffer(this.file.slice(f,f+h)))};e.prototype.h=b.prototype.h;e.prototype.set=b.prototype.set;e.prototype.j=b.prototype.j;e.prototype.$=b.prototype.$;e.prototype.H=b.prototype.H;e.prototype.pb=function(f){f()};e.prototype.fg=function(f){for(var h=[],k=Array.from(this.g.keys()).sort(function(m,
r){return m-r}),l=0,q=0;q<k.length;q++){var n=k[q],t=this.g.get(n);n*=256;n!==l&&(h.push(this.file.slice(l,n)),l=n);h.push(t);l+=t.length}l!==this.file.size&&h.push(this.file.slice(l));return new File(h,f)};var g="undefined"===typeof XMLHttpRequest?function(f,h){require("fs").stat(f,(k,l)=>{k?h(k):h(null,l.size)})}:function(f,h){Gb(f,{done:(k,l)=>{k=l.getResponseHeader("Content-Range")||"";(l=k.match(/\/(\d+)\s*$/))?h(null,+l[1]):h("`Range: bytes=...` header not supported (Got `"+k+"`)")},headers:{Range:"bytes=0-0"}})}})();function Hb(a,b,c,d,e,g){this.ka=new Ib(this,a,b,d,e,g);this.la=new Ib(this,a,c,!1,e,g);this.ta=this.ka;this.s=a;0===e?(this.g=496,this.ca=14,this.Ia=240):1===e&&(this.g=368,this.ca=15,this.Ia=248);this.i=this.g|516;this.h=46080;this.K=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,this.g&255|1,this.g>>8,0,0,this.i&255|1,this.i>>8,0,0,0,0,0,0,0,0,0,0,this.h&255|1,this.h>>8,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,this.ca,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.ib=[{size:8},{size:4},void 0,void 0,{size:16}];this.name="ide"+e;this.l=2;K(a.A,this.g|7,this,function(){Jb(this.s,this.ca);return this.Lg()});K(a.A,this.i|2,this,this.Lg);L(a.A,this.i|2,this,this.Uj);K(a.A,this.g|0,this,function(){return Kb(this.ta,1)},function(){return Kb(this.ta,2)},function(){return Kb(this.ta,4)});K(a.A,this.g|1,this,function(){return this.ta.error&
255});K(a.A,this.g|2,this,function(){return this.ta.ea&255});K(a.A,this.g|3,this,function(){return this.ta.wa&255});K(a.A,this.g|4,this,function(){return this.ta.na&255});K(a.A,this.g|5,this,function(){return this.ta.qa&255});K(a.A,this.g|6,this,function(){return this.ta.rc&255});L(a.A,this.g|0,this,function(f){Lb(this.ta,f,1)},function(f){Lb(this.ta,f,2)},function(f){Lb(this.ta,f,4)});L(a.A,this.g|1,this,function(f){this.ka.ad=(this.ka.ad<<8|f)&65535;this.la.ad=(this.la.ad<<8|f)&65535});L(a.A,this.g|
2,this,function(f){this.ka.ea=(this.ka.ea<<8|f)&65535;this.la.ea=(this.la.ea<<8|f)&65535});L(a.A,this.g|3,this,function(f){this.ka.wa=(this.ka.wa<<8|f)&65535;this.la.wa=(this.la.wa<<8|f)&65535});L(a.A,this.g|4,this,function(f){this.ka.na=(this.ka.na<<8|f)&65535;this.la.na=(this.la.na<<8|f)&65535});L(a.A,this.g|5,this,function(f){this.ka.qa=(this.ka.qa<<8|f)&65535;this.la.qa=(this.la.qa<<8|f)&65535});L(a.A,this.g|6,this,function(f){this.ta=f&16?this.la:this.ka;this.ka.rc=f;this.la.rc=f;this.ka.Hd=
this.la.Hd=f>>6&1;this.ka.head=this.la.head=f&15});this.j=this.ra=this.nd=0;L(a.A,this.g|7,this,function(f){Jb(this.s,this.ca);var h=this.ta;if(h.buffer)switch(h.o=f,h.error=0,f){case 8:h.i=0;h.g=0;h.h=0;Mb(h);h.S();break;case 16:h.status=80;h.na=0;h.S();break;case 248:h.status=80;var k=h.j-1;h.wa=k&255;h.na=k>>8&255;h.qa=k>>16&255;h.rc=h.rc&240|k>>24&15;h.S();break;case 39:h.status=80;k=h.j-1;h.wa=k&255;h.na=k>>8&255;h.qa=k>>16&255;h.wa|=k>>24<<8&65280;h.S();break;case 32:case 36:case 41:case 196:Nb(h,
f);break;case 48:case 52:case 57:case 197:var l=52===f||57===f;k=Ob(h,l);l=Pb(h,l);f=48===f||52===f;k*=h.l;l*=h.l;l+k>h.buffer.byteLength?(h.status=255,h.S()):(h.status=88,Qb(h,k),h.g=f?512:Math.min(k,512*h.L),h.X=l);break;case 144:h.S();h.error=257;h.status=80;break;case 145:h.status=80;h.S();break;case 160:h.J&&(h.status=88,Rb(h,12),h.g=12,h.ea=1,h.S());break;case 161:h.J?(Sb(h),h.status=88,h.na=20,h.qa=235):h.status=65;h.S();break;case 198:h.L=h.ea&255;h.status=80;h.S();break;case 37:case 200:k=
37===f;l=Ob(h,k);Pb(h,k)*h.l+l*h.l>h.buffer.byteLength?(h.status=255,h.S()):(h.status=88,h.oa.ra|=1);break;case 53:case 202:k=53===f;l=Ob(h,k);Pb(h,k)*h.l+l*h.l>h.buffer.byteLength?(h.status=255,h.S()):(h.status=88,h.oa.ra|=1);break;case 64:h.status=80;h.S();break;case 218:h.status=65;h.error=4;h.S();break;case 224:h.status=80;h.S();break;case 225:h.status=80;h.S();break;case 231:h.status=80;h.S();break;case 236:if(h.J){h.status=65;h.error=4;h.S();break}Sb(h);h.status=88;h.S();break;case 234:h.status=
80;h.S();break;case 239:h.status=80;h.S();break;case 222:h.status=80;h.S();break;case 245:h.status=80;h.S();break;case 249:h.status=65;h.error=4;break;default:h.status=65,h.error=4}else h.error=4,h.status=65,h.S()});K(a.A,this.h|4,this,void 0,void 0,this.vh);L(a.A,this.h|4,this,void 0,void 0,this.zh);K(a.A,this.h,this,this.xh,void 0,this.wh);L(a.A,this.h,this,this.Wf,void 0,this.Ah);K(a.A,this.h|2,this,this.yh);L(a.A,this.h|2,this,this.Xf);K(a.A,this.h|8,this,function(){return 0});K(a.A,this.h|10,
this,function(){return 0});Tb(a.u.Ha,this)}p=Hb.prototype;p.Lg=function(){return this.ta.buffer?this.ta.status:0};p.Uj=function(a){a&4&&(Jb(this.s,this.ca),Mb(this.ka),Mb(this.la));this.l=a};p.vh=function(){return this.nd};p.zh=function(a){this.nd=a};p.yh=function(){return this.ra};p.Xf=function(a){this.ra&=~(a&6)};p.wh=function(){return this.j|this.ra<<16};p.xh=function(){return this.j};p.Ah=function(a){this.Wf(a&255);this.Xf(a>>16&255)};
p.Wf=function(a){let b=this.j;this.j=a&9;if((b&1)!==(a&1))if(0===(a&1))this.ra&=-2;else switch(this.ra|=1,this.ta.o){case 37:case 200:Ub(this.ta);break;case 202:case 53:Vb(this.ta);break;case 160:Wb(this.ta)}};p.S=function(){0===(this.l&2)&&(this.ra|=4,this.s.Ka(this.ca))};p.$=function(){var a=[];a[0]=this.ka;a[1]=this.la;a[2]=this.g;a[3]=this.ca;a[4]=this.Ia;a[5]=this.i;a[6]=this.h;a[7]=this.name;a[8]=this.l;a[9]=this.nd;a[10]=this.ra;a[11]=this.ta===this.ka;a[12]=this.j;return a};
p.H=function(a){this.ka.H(a[0]);this.la.H(a[1]);this.g=a[2];this.ca=a[3];this.Ia=a[4];this.i=a[5];this.h=a[6];this.name=a[7];this.l=a[8];this.nd=a[9];this.ra=a[10];this.ta=a[11]?this.ka:this.la;this.j=a[12]};
function Ib(a,b,c,d,e,g){this.oa=a;this.v=g;this.Y=e;this.s=b;this.buffer=c;this.l=d?2048:512;this.J=d;this.F=this.C=this.D=this.j=0;this.buffer&&(this.j=this.buffer.byteLength/this.l,this.j!==(this.j|0)&&(this.j=Math.ceil(this.j)),d?(this.D=1,this.C=0):(this.D=16,this.C=63),this.F=this.j/this.D/this.C,this.F!==(this.F|0)&&(this.F=Math.floor(this.F)),a=b.u.Ic,a.W[57]|=1<<4*this.Y,a.W[18]=a.W[18]&15|240,a.W[27]=this.F&255,a.W[28]=this.F>>8&255,a.W[29]=this.D&255,a.W[30]=255,a.W[31]=255,a.W[32]=200,
a.W[33]=this.F&255,a.W[34]=this.F>>8&255,a.W[35]=this.C&255);this.B={Ng:0,Og:0,Qf:0,Rf:0,jg:!1};this.buffer=c;this.rc=this.head=this.qa=this.na=this.ad=this.wa=this.ea=this.Hd=0;this.status=80;this.L=128;this.i=this.error=0;this.data=new Uint8Array(65536);this.V=new Uint16Array(this.data.buffer);this.O=new Int32Array(this.data.buffer);this.g=this.h=0;this.T=this.o=-1;this.pa=this.X=0;this.P=new Set;this.ba=new Set;Object.seal(this)}
function Mb(a){a.J?(a.status=0,a.ea=1,a.error=1,a.wa=1,a.na=20,a.qa=235):(a.status=81,a.ea=1,a.error=1,a.wa=1,a.na=0,a.qa=0);for(const b of a.P)a.ba.add(b);a.P.clear()}p=Ib.prototype;p.S=function(){this.oa.S()};p.be=function(){this.status=80;var a=this.data.subarray(0,this.h);Xb(this,this.o,this.h/512);this.S();this.buffer.set(this.X,a,function(){});Yb(this,this.h)};
function Zb(a,b){var c=(b[7]<<8|b[8])*a.l;b=(b[2]<<24|b[3]<<16|b[4]<<8|b[5])*a.l;a.h=0;var d=a.qa<<8&65280|a.na&255;a.na=a.qa=0;65535===d&&d--;d>c&&(d=c);b>=a.buffer.byteLength?(a.status=255,a.S()):0===c?(a.status=80,a.i=0):(c=Math.min(c,a.buffer.byteLength-b),a.status=208,$b(a),a.fa(b,c,e=>{ac(a,e);a.status=88;a.ea=a.ea&-8|2;a.S();d&=-4;a.g=d;a.g>a.h&&(a.g=a.h);a.na=a.g&255;a.qa=a.g>>8&255;bc(a,c)}))}
function cc(a,b){var c=(b[7]<<8|b[8])*a.l;b=(b[2]<<24|b[3]<<16|b[4]<<8|b[5])*a.l;b>=a.buffer.byteLength?(a.status=255,a.S()):(a.status=208,$b(a),a.fa(b,c,d=>{bc(a,c);a.status=88;a.ea=a.ea&-8|2;ac(a,d);Wb(a)}))}function Wb(a){if(0!==(a.oa.ra&1)&&0!==(a.status&8)){var b=a.oa.nd,c=0,d=a.data;do{var e=a.s.g(b),g=a.s.Oa(b+4),f=a.s.od(b+7)&128;g||(g=65536);ra(a.s,d.subarray(c,Math.min(c+g,a.h)),e);c+=g;b+=8;if(c>=a.h&&!f)break}while(!f);a.status=80;a.oa.ra&=-2;a.ea=a.ea&-8|3;a.S()}}
function Kb(a,b){if(a.i<a.g){var c=1===b?a.data[a.i]:2===b?a.V[a.i>>>1]:a.O[a.i>>>2];a.i+=b;a.i>=a.g&&(160===a.o?a.g===a.h?(a.status=80,a.ea=a.ea&-8|3,a.S()):(a.status=88,a.ea=a.ea&-8|2,a.S(),b=a.qa<<8&65280|a.na&255,a.g+b>a.h?(a.na=a.h-a.g&255,a.qa=a.h-a.g>>8&255,a.g=a.h):a.g+=b):(a.error=0,a.i>=a.h?a.status=80:(b=196===a.o||41===a.o?Math.min(a.L,(a.h-a.g)/512):1,Xb(a,a.o,b),a.g+=512*b,a.status=88),a.S()));return c}a.i+=b;return 0}
function Lb(a,b,c){if(!(a.i>=a.g)&&(1===c?a.data[a.i++]=b:2===c?(a.V[a.i>>>1]=b,a.i+=2):(a.O[a.i>>>2]=b,a.i+=4),a.i===a.g))if(160===a.o){a.i=0;a.T=a.data[0];switch(a.T){case 0:Rb(a,0);a.g=a.h;a.status=80;break;case 3:Rb(a,a.data[4]);a.g=a.h;a.status=88;a.data[0]=240;a.data[2]=5;a.data[7]=8;break;case 18:b=a.data[4];a.status=88;a.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]);a.g=a.h=Math.min(36,b);break;case 26:Rb(a,a.data[4]);a.g=
a.h;a.status=88;break;case 30:Rb(a,0);a.g=a.h;a.status=80;break;case 37:b=a.j-1;ac(a,new Uint8Array([b>>24&255,b>>16&255,b>>8&255,b&255,0,0,a.l>>8&255,a.l&255]));a.g=a.h;a.status=88;break;case 40:a.ad&1?cc(a,a.data):Zb(a,a.data);break;case 66:b=a.data[8];Rb(a,Math.min(8,b));a.g=a.h;a.status=88;break;case 67:b=a.data[8]|a.data[7]<<8;c=a.data[9]>>6;Rb(a,b);a.g=a.h;0===c?(b=a.j,a.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,b>>24,b>>16&255,b>>8&255,b&255]))):1===c&&a.data.set(new Uint8Array([0,
10,1,1,0,0,0,0,0,0,0,0]));a.status=88;break;case 70:b=a.data[8]|a.data[7]<<8;b=Math.min(b,32);Rb(a,b);a.g=a.h;a.data[0]=b-4>>24&255;a.data[1]=b-4>>16&255;a.data[2]=b-4>>8&255;a.data[3]=b-4&255;a.data[6]=8;a.data[10]=3;a.status=88;break;case 81:Rb(a,0);a.g=a.h;a.status=80;break;case 82:a.status=81;a.h=0;a.error=80;break;case 90:b=a.data[8]|a.data[7]<<8;42===a.data[2]&&Rb(a,Math.min(30,b));a.g=a.h;a.status=88;break;case 189:Rb(a,a.data[9]|a.data[8]<<8);a.g=a.h;a.data[5]=1;a.status=88;break;case 74:a.status=
81;a.h=0;a.error=80;break;case 190:Rb(a,0);a.g=a.h;a.status=80;break;default:a.status=81,a.h=0,a.error=80}a.ea=a.ea&-8|2;0===(a.status&128)&&a.S();0===(a.status&128)&&0===a.h&&(a.ea|=1,a.status&=-9)}else a.i>=a.h?a.be():(a.status=88,a.g+=512,a.S())}
function Xb(a,b,c){a.ea-=c;36===b||41===b||52===b||57===b||37===b||53===b?(b=c+dc(a),a.wa=b&255|b>>16&65280,a.na=b>>8&255,a.qa=b>>16&255):a.Hd?(b=c+ec(a),a.wa=b&255,a.na=b>>8&255,a.qa=b>>16&255,a.head=a.head&-16|b&15):(b=c+gc(a),c=b/(a.D*a.C)|0,a.na=c&255,a.qa=c>>8&255,a.head=(b/a.C|0)%a.D&15,a.wa=b%a.C+1&255,gc(a))}
function Nb(a,b){var c=36===b||41===b,d=Ob(a,c);c=Pb(a,c);var e=32===b||36===b,g=d*a.l;c*=a.l;c+g>a.buffer.byteLength?(a.status=255,a.S()):(a.status=192,$b(a),a.fa(c,g,f=>{ac(a,f);a.status=88;a.g=e?512:Math.min(g,512*a.L);Xb(a,b,e?1:Math.min(d,a.C));a.S();bc(a,g)}))}
function Ub(a){var b=37===a.o,c=Ob(a,b);b=Pb(a,b);var d=c*a.l;b*=a.l;$b(a);a.fa(b,d,e=>{var g=a.oa.nd,f=0;do{var h=a.s.g(g),k=a.s.Oa(g+4),l=a.s.od(g+7)&128;k||(k=65536);ra(a.s,e.subarray(f,f+k),h);f+=k;g+=8}while(!l);Xb(a,a.o,c);a.status=80;a.oa.ra&=-2;a.o=-1;a.S();bc(a,d)})}
function Vb(a){var b=53===a.o,c=Ob(a,b),d=Pb(a,b);b=c*a.l;d*=a.l;var e=a.oa.nd,g=0;const f=new Uint8Array(b);do{var h=a.s.g(e),k=a.s.Oa(e+4),l=a.s.od(e+7)&128;k||(k=65536);f.set(a.s.Na.subarray(h,h+k),g);g+=k;e+=8}while(!l);a.buffer.set(d,f,()=>{Xb(a,a.o,c);a.status=80;a.S();a.oa.ra&=-2;a.o=-1});Yb(a,b)}function gc(a){return((a.na&255|a.qa<<8&65280)*a.D+a.head)*a.C+(a.wa&255)-1}function ec(a){return a.wa&255|a.na<<8&65280|a.qa<<16&16711680|(a.head&15)<<24}
function dc(a){return(a.wa&255|a.na<<8&65280|a.qa<<16&16711680|a.wa>>8<<24&4278190080)>>>0}function Pb(a,b){return b?dc(a):a.Hd?ec(a):gc(a)}function Ob(a,b){b?(a=a.ea,0===a&&(a=65536)):(a=a.ea&255,0===a&&(a=256));return a}
function Sb(a){if(a.rc&16)Rb(a,0);else{for(var b=0;512>b;b++)a.data[b]=0;b=Math.min(16383,a.F);ac(a,[64,a.J?133:0,b,b>>8,0,0,a.D,a.D>>8,a.C/512,a.C/512>>8,0,2,a.C,a.C>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,2,4,0,0,0,0,0,0,0,0,0,56,118,32,54,68,72,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,128,0,1,0,0,2,0,0,0,2,0,2,7,0,b,b>>8,a.D,a.D>>8,a.C,0,a.j&255,a.j>>8&255,a.j>>16&255,a.j>>24&255,0,0,a.j&255,a.j>>8&255,a.j>>16&255,
a.j>>24&255,0,0,160===a.o?0:7,160===a.o?0:4,0,0,30,0,30,0,30,0,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,116,0,64,0,64,0,116,0,64,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,a.j&255,a.j>>8&255,a.j>>16&255,a.j>>24&255]);a.h=512;a.g=512}}function Rb(a,b){Qb(a,b);for(var c=0;c<b+3>>2;c++)a.O[c]=0}function Qb(a,b){a.data.length<b&&(a.data=new Uint8Array(b+3&-4),a.V=new Uint16Array(a.data.buffer),a.O=new Int32Array(a.data.buffer));a.h=b;a.i=0}
function ac(a,b){Qb(a,b.length);a.data.set(b)}function $b(a){a.B.jg=!0;a.v.send("ide-read-start")}function bc(a,b){a.B.jg=!1;var c=b/a.l|0;a.B.Ng+=c;a.B.Qf+=b;a.v.send("ide-read-end",[a.Y,b,c])}function Yb(a,b){var c=b/a.l|0;a.B.Og+=c;a.B.Rf+=b;a.v.send("ide-write-end",[a.Y,b,c])}p.fa=function(a,b,c){const d=this.pa++;this.P.add(d);this.buffer.get(a,b,e=>{this.ba.delete(d)?this.P.has(d):(this.P.delete(d),c(e))})};
p.$=function(){var a=[];a[0]=this.ea;a[1]=this.F;a[2]=this.qa;a[3]=this.na;a[4]=this.i;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.rc;a[10]=this.error;a[11]=this.head;a[12]=this.D;a[13]=this.J;a[14]=this.Hd;a[15]=this.ad;a[16]=this.data;a[17]=this.h;a[18]=this.wa;a[19]=this.j;a[20]=this.l;a[21]=this.L;a[22]=this.C;a[23]=this.status;a[24]=this.X;a[25]=this.o;a[26]=this.g;a[27]=this.T;a[28]=this.buffer;return a};
p.H=function(a){this.ea=a[0];this.F=a[1];this.qa=a[2];this.na=a[3];this.i=a[4];this.rc=a[9];this.error=a[10];this.head=a[11];this.D=a[12];this.J=a[13];this.Hd=a[14];this.ad=a[15];this.data=a[16];this.h=a[17];this.wa=a[18];this.j=a[19];this.l=a[20];this.L=a[21];this.C=a[22];this.status=a[23];this.X=a[24];this.o=a[25];this.g=a[26];this.T=a[27];this.V=new Uint16Array(this.data.buffer);this.O=new Int32Array(this.data.buffer);this.buffer&&this.buffer.H(a[28])};function hc(a){this.qb=new Uint8Array(4);this.g=new Uint8Array(4);this.hd=new Uint8Array(4);this.jd=new Uint8Array(4);this.gd=new Int32Array(this.qb.buffer);new Int32Array(this.g.buffer);this.rg=new Int32Array(this.hd.buffer);this.tg=new Int32Array(this.jd.buffer);this.yb=[];this.u=[];this.s=a;for(var b=0;256>b;b++)this.yb[b]=void 0,this.u[b]=void 0;this.A=a.A;L(a.A,3324,this,function(c){ic(this,this.gd[0],c)},function(c){jc(this,this.gd[0],c)},function(c){var d=this.gd[0],e=d>>8&65535,g=d&255;d=
this.yb[e];e=this.u[e];if(d)if(16<=g&&40>g)if(e=e.ib[g-16>>2]){g>>=2;var f=d[g]&1;-1===(c|3|e.size-1)?(c=~(e.size-1)|f,0===f&&(d[g]=c)):0===f&&(d[g]=e.og);1===f&&(kc(this,e,d[g]&65534,c&65534),d[g]=c|1)}else d[g>>2]=0;else 48===g?d[g>>2]=e.sg?-1===(c|2047)?-e.sg|0:e.ci|0:0:4!==g&&(d[g>>>2]=c)});L(a.A,3325,this,function(c){ic(this,this.gd[0]+1|0,c)});L(a.A,3326,this,function(c){ic(this,this.gd[0]+2|0,c)},function(c){jc(this,this.gd[0]+2|0,c)});L(a.A,3327,this,function(c){ic(this,this.gd[0]+3|0,c)});
a.A.pd(3324,this,function(){return this.hd[0]},function(){return this.hd[1]},function(){return this.hd[2]},function(){return this.hd[3]});a.A.pd(3320,this,function(){return this.jd[0]},function(){return this.jd[1]},function(){return this.jd[2]},function(){return this.jd[3]});a.A.Lb(3320,this,function(c){this.qb[0]=c&252},function(c){2===(this.qb[1]&6)&&6===(c&6)?lc(a):this.qb[1]=c},function(c){this.qb[2]=c},function(c){this.qb[3]=c;c=this.qb[0]&252;var d=this.yb[this.qb[2]<<8|this.qb[1]];void 0!==
d?(this.tg[0]=-2147483648,this.rg[0]=c<d.byteLength?d[c>>2]:0):(this.rg[0]=-1,this.tg[0]=0)});Tb(this,{Ia:0,K:[134,128,55,18,0,0,0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],ib:[],name:"82441FX PMC"});this.i={Ia:8,K:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],ib:[],name:"82371SB PIIX3 ISA"};
this.j=Tb(this,this.i);this.h=new Uint8Array(this.j.buffer)}hc.prototype.$=function(){for(var a=[],b=0;256>b;b++)a[b]=this.yb[b];a[256]=this.qb;a[257]=this.g;a[258]=this.hd;a[259]=this.jd;return a};hc.prototype.H=function(a){for(var b=0;256>b;b++){var c=this.u[b],d=a[b];if(c&&d){for(var e=0;e<c.ib.length;e++){var g=d[4+e];if(g&1){var f=c.ib[e];kc(this,f,f.og&65534,g&65534)}}this.yb[b].set(d)}}this.qb.set(a[256]);this.g.set(a[257]);this.hd.set(a[258]);this.jd.set(a[259])};
function ic(a,b,c){var d=b&255;(new Uint8Array(a.yb[b>>8&65535].buffer))[d]=c}function jc(a,b,c){var d=b&255;a=new Uint16Array(a.yb[b>>8&65535].buffer);!a||16<=d&&44>d||(a[d>>>1]=c)}function Tb(a,b){var c=b.Ia,d=new Int32Array(64);d.set(new Int32Array((new Uint8Array(b.K)).buffer));a.yb[c]=d;a.u[c]=b;c=d.slice(4,10);for(var e=0;e<b.ib.length;e++){var g=b.ib[e];if(g){var f=c[e],h=f&1;g.og=f;g.entries=[];if(0!==h)for(f&=-2,h=0;h<g.size;h++)g.entries[h]=a.A.ports[f+h]}}return d}
function kc(a,b,c,d){for(var e=b.size,g=a.A.ports,f=0;f<e;f++){4096<=c+f&&(g[c+f]=gb(a.A));var h=b.entries[f];4096<=d+f&&(g[d+f]=h)}}hc.prototype.Aa=function(a){this.s.Ka(this.h[96+((this.yb[a][15]>>8&255)-1+((a>>3)-1&255)&3)])};function mc(a,b){Jb(a.s,a.h[96+((a.yb[b][15]>>8&255)+(b>>3&255)-2&3)])};function nc(a,b){this.A=a.A;this.s=a;this.eb=a.u.eb;this.h=0;this.L=new Uint8Array(10);this.O=0;this.j=null;this.g=new Uint8Array(10);this.l=this.i=0;this.F=b;this.J=this.C=this.V=this.ba=this.Y=this.X=0;this.P=1;this.o=0;if(b){var c={[163840]:{type:1,kb:40,jb:8,gb:1},[184320]:{type:1,kb:40,jb:9,gb:1},[204800]:{type:1,kb:40,jb:10,gb:1},[327680]:{type:1,kb:40,jb:8,gb:2},[368640]:{type:1,kb:40,jb:9,gb:2},[409600]:{type:1,kb:40,jb:10,gb:2},[737280]:{type:3,kb:80,jb:9,gb:2},[1228800]:{type:2,kb:80,jb:15,
gb:2},[1474560]:{type:4,kb:80,jb:18,gb:2},[1763328]:{type:5,kb:82,jb:21,gb:2},[2949120]:{type:5,kb:80,jb:36,gb:2},512:{type:1,kb:1,jb:1,gb:1}},d=b.byteLength;d=c[d];d||(d=1474560<b.byteLength?2949120:1474560,d=c[d]);a.u.Ic.W[16]=d.type<<4;a=d.jb;b=d.gb;d=d.kb;this.B=a;this.D=b;this.T=d}else a.u.Ic.W[16]=64,this.T=this.D=this.B=0;K(this.A,1008,this,this.kj);K(this.A,1010,this,this.lj);K(this.A,1012,this,this.nj);K(this.A,1013,this,this.oj);K(this.A,1015,this,this.qj);L(this.A,1010,this,this.mj);L(this.A,
1013,this,this.pj)}p=nc.prototype;p.$=function(){var a=[];a[0]=this.h;a[1]=this.L;a[2]=this.O;a[4]=this.g;a[5]=this.i;a[6]=this.l;a[8]=this.X;a[9]=this.Y;a[10]=this.ba;a[11]=this.V;a[12]=this.C;a[13]=this.J;a[14]=this.P;a[15]=this.o;a[16]=this.B;a[17]=this.D;a[18]=this.T;return a};
p.H=function(a){this.h=a[0];this.L=a[1];this.O=a[2];this.j=a[3];this.g=a[4];this.i=a[5];this.l=a[6];this.X=a[8];this.Y=a[9];this.ba=a[10];this.V=a[11];this.C=a[12];this.J=a[13];this.P=a[14];this.o=a[15];this.B=a[16];this.D=a[17];this.T=a[18]};p.kj=function(){return 0};p.nj=function(){var a=128;this.i<this.l&&(a|=80);0===(this.o&8)&&(a|=32);return a};p.qj=function(){return 0};p.oj=function(){return this.i<this.l?(Jb(this.s,6),this.g[this.i++]):255};
p.pj=function(a){if(this.F)if(0<this.h)this.L[this.O++]=a,this.h--,0===this.h&&this.j.call(this,this.L);else{switch(a){case 3:this.j=this.Ih;this.h=2;break;case 4:this.j=this.mh;this.h=1;break;case 5:case 69:case 197:this.j=function(b){oc(this,!0,b)};this.h=8;break;case 230:this.j=function(b){oc(this,!1,b)};this.h=8;break;case 7:this.j=this.lh;this.h=1;break;case 8:this.i=0;this.l=2;this.g[0]=32;this.g[1]=this.C;break;case 74:this.j=this.Ej;this.h=1;break;case 15:this.h=2;this.j=this.fh;break;case 14:this.g[0]=
128,this.i=0,this.l=1,this.h=0}this.O=0}};p.lj=function(){return this.o};p.mj=function(a){4===(a&4)&&0===(this.o&4)&&this.s.Ka(6);this.o=a};p.mh=function(){this.i=0;this.l=1;this.g[0]=32};p.fh=function(a){this.C=a[1];this.J=a[0]>>2&1;this.Aa()};p.lh=function(){this.Aa()};function oc(a,b,c){var d=c[2],e=c[1],g=c[3],f=128<<c[4],h=c[5]-c[3]+1,k=((d+a.D*e)*a.B+g-1)*f;a.F&&(b?a.eb.be(a.F,k,h*f,2,a.done.bind(a,c,e,d,g)):pc(a.eb,a.F,k,a.done.bind(a,c,e,d,g)))}
p.done=function(a,b,c,d,e){e||(d++,d>this.B&&(d=1,c++,c>=this.D&&(c=0,b++)),this.C=b,this.J=c,this.P=d,this.i=0,this.l=7,this.g[0]=c<<2|32,this.g[1]=0,this.g[2]=0,this.g[3]=b,this.g[4]=c,this.g[5]=d,this.g[6]=a[4],this.Aa())};p.Ih=function(){};p.Ej=function(){this.i=0;this.l=7;this.g[0]=0;this.g[1]=0;this.g[2]=0;this.g[3]=0;this.g[4]=0;this.g[5]=0;this.g[6]=0;this.Aa()};p.Aa=function(){this.o&8&&this.s.Ka(6)};function ra(a,b,c){b.length&&(a.Me(c),a.Me(c+b.length-1),a.Uh(c,c+b.length),a.Na.set(b,c))};function qc(a){this.s=a;this.o=new Uint8Array(8);this.B=new Uint8Array(8);this.g=new Uint16Array(8);this.j=new Uint16Array(8);this.h=new Uint16Array(8);this.l=new Uint16Array(8);this.Yb=new Uint8Array(8);this.C=new Uint8Array(8);this.cf=[];this.i=0;a=a.A;L(a,0,this,this.Dc.bind(this,0));L(a,2,this,this.Dc.bind(this,1));L(a,4,this,this.Dc.bind(this,2));L(a,6,this,this.Dc.bind(this,3));L(a,1,this,this.Fc.bind(this,0));L(a,3,this,this.Fc.bind(this,1));L(a,5,this,this.Fc.bind(this,2));L(a,7,this,this.Fc.bind(this,
3));K(a,0,this,this.Cc.bind(this,0));K(a,2,this,this.Cc.bind(this,1));K(a,4,this,this.Cc.bind(this,2));K(a,6,this,this.Cc.bind(this,3));K(a,1,this,this.Ec.bind(this,0));K(a,3,this,this.Ec.bind(this,1));K(a,5,this,this.Ec.bind(this,2));K(a,7,this,this.Ec.bind(this,3));L(a,192,this,this.Dc.bind(this,4));L(a,196,this,this.Dc.bind(this,5));L(a,200,this,this.Dc.bind(this,6));L(a,204,this,this.Dc.bind(this,7));L(a,194,this,this.Fc.bind(this,4));L(a,198,this,this.Fc.bind(this,5));L(a,202,this,this.Fc.bind(this,
6));L(a,206,this,this.Fc.bind(this,7));K(a,192,this,this.Cc.bind(this,4));K(a,196,this,this.Cc.bind(this,5));K(a,200,this,this.Cc.bind(this,6));K(a,204,this,this.Cc.bind(this,7));K(a,194,this,this.Ec.bind(this,4));K(a,198,this,this.Ec.bind(this,5));K(a,202,this,this.Ec.bind(this,6));K(a,206,this,this.Ec.bind(this,7));L(a,135,this,this.Hc.bind(this,0));L(a,131,this,this.Hc.bind(this,1));L(a,129,this,this.Hc.bind(this,2));L(a,130,this,this.Hc.bind(this,3));L(a,143,this,this.Hc.bind(this,4));L(a,139,
this,this.Hc.bind(this,5));L(a,137,this,this.Hc.bind(this,6));L(a,138,this,this.Hc.bind(this,7));K(a,135,this,this.Gc.bind(this,0));K(a,131,this,this.Gc.bind(this,1));K(a,129,this,this.Gc.bind(this,2));K(a,130,this,this.Gc.bind(this,3));K(a,143,this,this.Gc.bind(this,4));K(a,139,this,this.Gc.bind(this,5));K(a,137,this,this.Gc.bind(this,6));K(a,138,this,this.Gc.bind(this,7));L(a,1159,this,this.md.bind(this,0));L(a,1155,this,this.md.bind(this,1));L(a,1153,this,this.md.bind(this,2));L(a,1154,this,this.md.bind(this,
3));L(a,1163,this,this.md.bind(this,5));L(a,1161,this,this.md.bind(this,6));L(a,1162,this,this.md.bind(this,7));K(a,1159,this,this.ld.bind(this,0));K(a,1155,this,this.ld.bind(this,1));K(a,1153,this,this.ld.bind(this,2));K(a,1154,this,this.ld.bind(this,3));K(a,1163,this,this.ld.bind(this,5));K(a,1161,this,this.ld.bind(this,6));K(a,1162,this,this.ld.bind(this,7));L(a,10,this,this.Ig.bind(this,0));L(a,212,this,this.Ig.bind(this,4));L(a,15,this,this.Hg.bind(this,0));L(a,222,this,this.Hg.bind(this,4));
K(a,15,this,this.Gg.bind(this,0));K(a,222,this,this.Gg.bind(this,4));L(a,11,this,this.Fg.bind(this,0));L(a,214,this,this.Fg.bind(this,4));L(a,12,this,this.Eg);L(a,216,this,this.Eg)}p=qc.prototype;p.$=function(){return[this.o,this.B,this.g,this.j,this.h,this.l,this.Yb,this.C,this.i]};p.H=function(a){this.o=a[0];this.B=a[1];this.g=a[2];this.j=a[3];this.h=a[4];this.l=a[5];this.Yb=a[6];this.C=a[7];this.i=a[8]};p.Fc=function(a,b){this.h[a]=rc(this,this.h[a],b,!1);this.l[a]=rc(this,this.l[a],b,!0)};
p.Ec=function(a){return sc(this,this.h[a])};p.Dc=function(a,b){this.g[a]=rc(this,this.g[a],b,!1);this.j[a]=rc(this,this.j[a],b,!0)};p.Cc=function(a){return sc(this,this.g[a])};p.md=function(a,b){this.B[a]=b};p.ld=function(a){return this.B[a]};p.Hc=function(a,b){this.o[a]=b};p.Gc=function(a){return this.o[a]};p.Ig=function(a,b){tc(this,(b&3)+a,b&4?1:0)};p.Hg=function(a,b){for(var c=0;4>c;c++)tc(this,a+c,b&1<<c)};
p.Gg=function(a){var b=0|this.Yb[a+0];b|=this.Yb[a+1]<<1;b|=this.Yb[a+2]<<2;return b|=this.Yb[a+3]<<3};p.Fg=function(a,b){this.C[(b&3)+a]=b};p.Eg=function(){this.i=0};function tc(a,b,c){if(a.Yb[b]!==c&&(a.Yb[b]=c,!c))for(c=0;c<a.cf.length;c++)a.cf[c].Je.call(a.cf[c].Gf,b)}function pc(a,b,c,d){var e=a.h[2]+1,g=uc(a,2);if(c+e>b.byteLength)d(!0);else{var f=a.s;a.g[2]+=e;b.get(c,e,function(h){ra(f,h,g);d(!1)})}}
p.be=function(a,b,c,d,e){var g=this.h[d]+1&65535,f=5<=d?2:1,h=g*f,k=uc(this,d),l=!1,q=!1,n=this.C[d]&16;c<h?(g=Math.floor(c/f),h=g*f,l=!0):c>h&&(q=!0);b+h>a.byteLength?e(!0):(this.g[d]+=g,this.h[d]-=g,!l&&n&&(this.g[d]=this.j[d],this.h[d]=this.l[d]),a.set(b,this.s.Na.subarray(k,k+h),()=>{q&&n?this.be(a,b+h,c-h,d,e):e(!1)}))};function uc(a,b){var c=a.g[b];5<=b&&(c<<=1);c=c&65535|a.o[b]<<16;return c|=a.B[b]<<24}function rc(a,b,c,d){d||(a.i^=1);return a.i?b&-256|c:b&-65281|c<<8}
function sc(a,b){a.i^=1;return a.i?b&255:b>>8&255};function vc(a,b){this.s=a;this.v=b;this.i=new Float64Array(3);this.j=new Uint16Array(3);this.g=new Uint8Array(4);this.h=new Uint8Array(4);this.Sc=new Uint8Array(4);this.B=new Uint8Array(4);this.l=new Uint8Array(4);this.o=new Uint16Array(3);this.mb=new Uint16Array(3);K(a.A,97,this,function(){var c=nb(),d=66.66666666666667*c&1;c=wc(this,2,c);return d<<4|c<<5});L(a.A,97,this,function(c){c&1?this.v.send("pcspeaker-enable"):this.v.send("pcspeaker-disable")});K(a.A,64,this,function(){return xc(this,0)});
K(a.A,65,this,function(){return xc(this,1)});K(a.A,66,this,function(){return xc(this,2)});L(a.A,64,this,function(c){yc(this,0,c)});L(a.A,65,this,function(c){yc(this,1,c)});L(a.A,66,this,function(c){yc(this,2,c);this.v.send("pcspeaker-update",[this.Sc[2],this.mb[2]])});L(a.A,67,this,this.C)}vc.prototype.$=function(){var a=[];a[0]=this.g;a[1]=this.h;a[2]=this.Sc;a[3]=this.B;a[4]=this.l;a[5]=this.o;a[6]=this.mb;a[7]=this.i;a[8]=this.j;return a};
vc.prototype.H=function(a){this.g=a[0];this.h=a[1];this.Sc=a[2];this.B=a[3];this.l=a[4];this.o=a[5];this.mb=a[6];this.i=a[7];this.j=a[8]};vc.prototype.sb=function(a,b){var c=100;b||(this.h[0]&&wc(this,0,a)?(this.j[0]=zc(this,0,a),this.i[0]=a,Jb(this.s,0),this.s.Ka(0),0===this.Sc[0]&&(this.h[0]=0)):Jb(this.s,0),this.h[0]&&(c=(this.j[0]-Math.floor(1193.1816666*(a-this.i[0])))/1193.1816666));return c};
function zc(a,b,c){if(!a.h[b])return 0;c=a.j[b]-Math.floor(1193.1816666*(c-a.i[b]));a=a.mb[b];c>=a?c%=a:0>c&&(c=c%a+a);return c}function wc(a,b,c){c-=a.i[b];return 0>c?!0:a.j[b]<Math.floor(1193.1816666*c)}function xc(a,b){var c=a.l[b];if(c)return a.l[b]--,2===c?a.o[b]&255:a.o[b]>>8;c=a.g[b];3===a.Sc[b]&&(a.g[b]^=1);a=zc(a,b,nb());return c?a&255:a>>8}
function yc(a,b,c){a.mb[b]=a.g[b]?a.mb[b]&-256|c:a.mb[b]&255|c<<8;3===a.B[b]&&a.g[b]||(a.mb[b]||(a.mb[b]=65535),a.j[b]=a.mb[b],a.h[b]=!0,a.i[b]=nb());3===a.B[b]&&(a.g[b]^=1)}vc.prototype.C=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.l[c]=2,b=zc(this,c,nb()),this.o[c]=b?b-1:0):(6<=b&&(b&=-5),this.g[c]=1===a?0:1,0===c&&Jb(this.s,0),this.Sc[c]=b,this.B[c]=a,2===c&&this.v.send("pcspeaker-update",[this.Sc[2],this.mb[2]])))};var Ac=Uint32Array.from([655360,655360,720896,753664]),Bc=Uint32Array.from([131072,65536,32768,32768]);
function Cc(a,b,c){this.s=a;this.v=b;this.ha=c;this.D=0;this.sc=14;this.qc=15;this.L=80;this.Tb=25;this.ze=this.Ea=this.Pd=this.mc=0;this.Id=[];this.Ac=this.Ba=0;this.cb=new Uint8Array(25);this.C=this.O=this.zc=this.P=this.g=this.i=this.Qb=this.Rb=this.Fa=0;this.uc=!0;this.Da=!1;setTimeout(()=>{b.send("screen-set-mode",this.Da)},0);this.$a=new Int32Array(256);this.h=0;this.ke=45253;this.Za=this.Pa=0;this.La=!1;this.Mb=32;this.ud=this.Sa=0;this.K=[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.Ia=144;this.ib=[{size:c}];this.sg=65536;this.ci=4272947200;this.name="vga";this.B={hg:!1,Fj:0,Gj:0,Pf:0};this.pa=this.tb=this.ba=this.F=0;this.X=255;this.Zb=new Uint8Array(16);this.l=-1;this.Ub=32;this.Rc=this.Sb=this.Cd=this.Ta=0;this.Wb=-1;this.Vb=15;this.bb=this.Xb=0;this.Pb=-1;this.Ra=this.kc=this.xc=0;this.vc=255;this.Y=this.V=this.T=this.Qa=this.wc=this.Ob=0;this.j=this.$c=255;c=a.A;
L(c,960,this,this.Pi);K(c,960,this,this.Ag,this.Oi);K(c,961,this,this.Bg);L(c,962,this,this.Qi);c.Lb(964,this,this.Si,this.Ui);K(c,964,this,this.Ri);K(c,965,this,this.Ti);c.Lb(974,this,this.ej,this.gj);K(c,974,this,this.dj);K(c,975,this,this.fj);K(c,966,this,this.Vi);L(c,966,this,this.Wi);L(c,967,this,this.Yi);K(c,967,this,this.Xi);L(c,968,this,this.$i);K(c,968,this,this.Zi);L(c,969,this,this.bj);K(c,969,this,this.aj);K(c,972,this,this.cj);c.Lb(980,this,this.ij,this.jj);K(c,980,this,this.hj);K(c,
981,this,this.Cg,()=>this.Cg());K(c,970,this,function(){return 0});K(c,986,this,this.Dg);K(c,954,this,this.Dg);this.ub=-1;this.J=0;L(c,462,this,void 0,this.ei);L(c,463,this,void 0,this.gi);K(c,463,this,void 0,this.fi);void 0===this.ha||262144>this.ha?this.ha=262144:this.ha&65535&&(this.ha|=65535,this.ha++);const d=a.ah(this.ha);this.Ff=Q(Uint8Array,a.Ja,d,this.ha);this.Zd=this.ha;this.Yd=0;this.ae=this.ha;this.$d=0;this.Fb=null;b.register("screen-fill-buffer",function(){if(this.Da){if(0===this.Fb.data.byteLength){var g=
new Uint8ClampedArray(this.s.Ja.buffer,this.jf,4*this.Ea*this.ze);this.Fb=new ImageData(g,this.Ea,this.ze);Dc(this)}if(this.La){g=0;var f=this.Za;if(8===this.Mb)for(var h=new Int32Array(this.s.Ja.buffer,this.jf,this.mc*this.Pd),k=new Uint8Array(this.s.Ja.buffer,this.Ff.byteOffset,this.ha),l=0;l<h.length;l++){var q=this.$a[k[l]];h[l]=q&65280|q<<16|q>>16|4278190080}else this.s.eh(this.Mb,this.ud),l=15===this.Mb?2:this.Mb/8,g=((this.s.dh[0]/l|0)-this.ud)/this.Pa|0,f=(((this.s.bh[0]/l|0)-this.ud)/this.Pa|
0)+1;g<f&&(g=Math.max(g,0),f=Math.min(f,this.Za),this.v.send("screen-fill-buffer-end",[{Fb:this.Fb,Bf:0,Cf:g,De:0,Ee:g,gf:this.Pa,ff:f-g}]))}else{g=Math.min(this.$d|15,524287);l=Ec(this);q=~this.Fa&3;f=this.kc&96;h=this.Ta&64;for(k=this.ae&-16;k<=g;){var n=k>>>l;if(q){var t=k/this.Ea|0,m=k-this.Ea*t;switch(q){case 1:n=(t&1)<<13;t>>>=1;break;case 2:n=(t&1)<<14;t>>>=1;break;case 3:n=(t&3)<<13,t>>>=2}n|=(t*this.Ea+m>>>l)+this.Ba}t=this.Ve[n];m=this.We[n];var r=this.Xe[n],x=this.Ye[n];n=new Uint8Array(8);
switch(f){case 0:t<<=0;m<<=1;r<<=2;x<<=3;for(var w=7;0<=w;w--)n[7-w]=t>>w&1|m>>w&2|r>>w&4|x>>w&8;break;case 32:n[0]=t>>6&3|r>>4&12;n[1]=t>>4&3|r>>2&12;n[2]=t>>2&3|r>>0&12;n[3]=t>>0&3|r<<2&12;n[4]=m>>6&3|x>>4&12;n[5]=m>>4&3|x>>2&12;n[6]=m>>2&3|x>>0&12;n[7]=m>>0&3|x<<2&12;break;case 64:case 96:n[0]=t>>4&15,n[1]=t>>0&15,n[2]=m>>4&15,n[3]=m>>0&15,n[4]=r>>4&15,n[5]=r>>0&15,n[6]=x>>4&15,n[7]=x>>0&15}if(h)for(t=w=0;4>w;w++,k++,t+=2)this.Kd[k]=n[t]<<4|n[t+1];else for(w=0;8>w;w++,k++)this.Kd[k]=n[w]}h=this.Zd;
g=Math.min(this.Yd,524287);f=new Int32Array(this.s.Ja.buffer,this.jf,this.Ea*this.ze);l=255;q=0;this.Ta&128&&(l&=207,q|=this.Rc<<4&48);if(this.Ta&64)for(;h<=g;h++)k=this.Kd[h]&l|q,k=this.$a[k],f[h]=k&65280|k<<16|k>>16|4278190080;else for(l&=63,q|=this.Rc<<4&192;h<=g;h++)k=this.Zb[this.Kd[h]&this.Cd]&l|q,k=this.$a[k],f[h]=k&65280|k<<16|k>>16|4278190080;this.v.send("screen-fill-buffer-end",this.Id)}this.Zd=this.ha;this.Yd=0;this.ae=this.ha;this.$d=0}Fc(this)},this);this.o=new Uint8Array(262144);this.Ve=
new Uint8Array(this.o.buffer,0,65536);this.We=new Uint8Array(this.o.buffer,65536,65536);this.Xe=new Uint8Array(this.o.buffer,131072,65536);this.Ye=new Uint8Array(this.o.buffer,196608,65536);this.Kd=new Uint8Array(524288);var e=this;hb(c,655360,131072,function(g){return Gc(e,g)},function(g,f){if(e.La&&e.Da&&e.uc)e.s.df((g-655360|e.Sa)+3758096384|0,f);else{var h=e.Qa>>2&3;g-=Ac[h];if(!(0>g||g>=Bc[h]))if(e.Da){var k=f;f=Hc(e.vc);var l=Ic(e.Ob);h=Ic(e.wc);switch(e.kc&3){case 0:k=(k|k<<8)>>>(e.Ra&7)&255;
var q=Hc(k);k=Ic(e.Ob);q=Jc(e,(q|h&k)&(~h|k),e.h);q=f&q|~f&e.h;break;case 1:q=e.h;break;case 2:q=Ic(k);q=Jc(e,q,e.h);q=f&q|~f&e.h;break;case 3:k=(k|k<<8)>>>(e.Ra&7)&255,f&=Hc(k),q=f&l|~f&e.h}f=15;switch(e.Xb&12){case 0:f=5<<(g&1);g&=-2;break;case 8:case 12:f=1<<(g&3),g&=-4}f&=e.Vb;f&1&&(e.Ve[g]=q>>0&255);f&2&&(e.We[g]=q>>8&255);f&4&&(e.Xe[g]=q>>16&255);f&8&&(e.Ye[g]=q>>24&255);f=Kc(e,g);q=f+7;f<e.ae&&(e.ae=f);q>e.$d&&(e.$d=q);f<e.Zd&&(e.Zd=f);q>e.Yd&&(e.Yd=q)}else e.Vb&3&&(q=g,h=(q>>1)-e.Ba,g=h/e.L|
0,h%=e.L,q&1?(l=f,k=e.o[q&-2]):(k=f,l=e.o[q|1]),e.v.send("screen-put-char",[g,h,k,e.$a[e.X&e.Zb[l>>4&15]],e.$a[e.X&e.Zb[l&15]]]),e.o[q]=f)}});Tb(a.u.Ha,this)}p=Cc.prototype;
p.$=function(){var a=[];a[0]=this.ha;a[1]=this.D;a[2]=this.sc;a[3]=this.qc;a[4]=this.L;a[5]=this.Tb;a[6]=this.o;a[7]=this.pa;a[8]=this.Ba;a[9]=this.Da;a[10]=this.$a;a[11]=this.h;a[12]=this.T;a[13]=this.V;a[14]=this.Qa;a[15]=this.Pa;a[16]=this.Za;a[17]=this.Fa;a[18]=this.La;a[19]=this.Mb;a[20]=this.Sa;a[21]=this.ud;a[22]=this.F;a[23]=this.ba;a[24]=this.tb;a[25]=this.Zb;a[26]=this.Wb;a[27]=this.Vb;a[28]=this.Xb;a[29]=this.Pb;a[30]=this.xc;a[31]=this.kc;a[32]=this.Ra;a[33]=this.vc;a[34]=this.Y;a[35]=
this.$c;a[36]=this.j;a[37]=this.ub;a[38]=this.J;a[39]=this.Ff;a[40]=this.uc;a[41]=this.l;a[42]=this.O;a[43]=this.Ob;a[44]=this.wc;a[45]=this.Ac;a[46]=this.cb;a[47]=this.Rb;a[48]=this.Qb;a[49]=this.i;a[50]=this.g;a[51]=this.P;a[52]=this.zc;a[53]=this.O;a[54]=this.Ub;a[55]=this.Ta;a[56]=this.Cd;a[57]=this.Sb;a[58]=this.Rc;a[59]=this.bb;a[60]=this.C;a[61]=this.Kd;a[62]=this.X;return a};
p.H=function(a){this.ha=a[0];this.D=a[1];this.sc=a[2];this.qc=a[3];this.L=a[4];this.Tb=a[5];a[6]&&this.o.set(a[6]);this.pa=a[7];this.Ba=a[8];this.Da=a[9];this.$a=a[10];this.h=a[11];this.T=a[12];this.V=a[13];this.Qa=a[14];this.Pa=a[15];this.Za=a[16];this.Fa=a[17];this.La=a[18];this.Mb=a[19];this.Sa=a[20];this.ud=a[21];this.F=a[22];this.ba=a[23];this.tb=a[24];this.Zb=a[25];this.Wb=a[26];this.Vb=a[27];this.Xb=a[28];this.Pb=a[29];this.xc=a[30];this.kc=a[31];this.Ra=a[32];this.vc=a[33];this.Y=a[34];this.$c=
a[35];this.j=a[36];this.ub=a[37];this.J=a[38];this.Ff.set(a[39]);this.uc=a[40];this.l=a[41];this.O=a[42];this.Ob=a[43];this.wc=a[44];this.Ac=a[45];this.cb.set(a[46]);this.Rb=a[47];this.Qb=a[48];this.i=a[49];this.g=a[50];this.P=a[51];this.zc=a[52];this.O=a[53];this.Ub=a[54];this.Ta=a[55];this.Cd=a[56];this.Sb=a[57];this.Rc=a[58];this.bb=a[59];this.C=a[60];a[61]&&this.Kd.set(a[61]);this.X=void 0===a[62]?255:a[62];this.v.send("screen-set-mode",this.Da);this.Da?(this.Pd=this.mc=0,this.La?(this.qd(this.Pa,
this.Za,this.Mb,this.Pa,this.Za),Dc(this)):(Lc(this),Dc(this),Mc(this))):(this.rd(this.L,this.Tb),this.xd(),this.wd());Nc(this)};
function Gc(a,b){if(a.La&&a.uc)return a.s.od((b-655360|a.Sa)+3758096384|0);var c=a.Qa>>2&3;b-=Ac[c];if(0>b||b>=Bc[c])return 0;a.h=a.Ve[b];a.h|=a.We[b]<<8;a.h|=a.Xe[b]<<16;a.h|=a.Ye[b]<<24;if(a.kc&8)return c=255,a.V&1&&(c&=a.Ve[b]^~(a.T&1?255:0)),a.V&2&&(c&=a.We[b]^~(a.T&2?255:0)),a.V&4&&(c&=a.Xe[b]^~(a.T&4?255:0)),a.V&8&&(c&=a.Ye[b]^~(a.T&8?255:0)),c;c=a.xc;a.Da?a.Xb&8?(c=b&3,b&=-4):a.kc&16&&(c=b&1,b&=-2):c=0;return a.o[c<<16|b]}function Hc(a){return a|a<<8|a<<16|a<<24}
function Ic(a){return(a&1?255:0)|(a&2?255:0)<<8|(a&4?255:0)<<16|(a&8?255:0)<<24}function Jc(a,b,c){switch(a.Ra&24){case 8:return b&c;case 16:return b|c;case 24:return b^c}return b}function Oc(a){for(var b=a.Ba<<1,c,d,e=0;e<a.Tb;e++)for(var g=0;g<a.L;g++)c=a.o[b],d=a.o[b|1],a.v.send("screen-put-char",[e,g,c,a.$a[a.X&a.Zb[d>>4&15]],a.$a[a.X&a.Zb[d&15]]]),b+=2}p.wd=function(){var a=(this.D-this.Ba)/this.L|0,b=(this.D-this.Ba)%this.L;a=Math.min(this.Tb-1,a);this.v.send("screen-update-cursor",[a,b])};
function Nc(a){a.Da?a.La?a.s.lg():(a.Zd=0,a.Yd=524288):Oc(a)}function Mc(a){a.Da&&!a.La&&(a.ae=0,a.$d=524288,Nc(a))}p.va=function(){};function Ec(a){var b=128+(~a.P&a.Fa&64);b-=a.P&64;b-=a.Ta&64;return b>>>6}function Kc(a,b){var c=Ec(a);if(~a.Fa&3){var d=b-a.Ba;d&=a.Fa<<13|-24577;d<<=c;var e=d/a.Ea|0;d%=a.Ea;switch(a.Fa&3){case 2:e=e<<1|b>>13&1;break;case 1:e=e<<1|b>>14&1;break;case 0:e=e<<2|b>>13&3}return e*a.Ea+d+(a.Ba<<c)}return b<<c}
function Pc(a,b){a.Y&128&&(b>>>=1);b=Math.ceil(b/(1+(a.Y&31)));a.Fa&1||(b<<=1);a.Fa&2||(b<<=1);return b}p.rd=function(a,b){this.L=a;this.Tb=b;this.v.send("screen-set-size-text",[a,b])};
p.qd=function(a,b,c,d,e){if(!this.B.hg||this.B.Pf!==c||this.mc!==a||this.Pd!==b||this.Ea!==d||this.ze!==e){this.mc=a;this.Pd=b;this.Ea=d;this.ze=e;this.B.Pf=c;this.B.hg=!0;this.B.Fj=a;this.B.Gj=b;if("undefined"!==typeof ImageData){const g=d*e,f=this.s.$g(g)>>>0;this.jf=f;this.Fb=new ImageData(new Uint8ClampedArray(this.s.Ja.buffer,f,4*g),d,e);this.s.lg()}this.v.send("screen-set-size-graphical",[a,b,d,e,c])}};
function Lc(a){if(!a.La){var b=Math.min(1+a.Rb,a.Qb),c=Math.min(1+a.i,a.g);if(b&&c)if(a.Da){b<<=3;var d=a.O<<4;a.Ta&64&&(b>>>=1,d>>>=1);var e=a.O<<2;a.P&64?e<<=1:a.Fa&64&&(e>>>=1);a.qd(b,Pc(a,c),8,d,Math.ceil(Bc[0]/e));Fc(a);Dc(a)}else a.Y&128&&(c>>>=1),c=c/(1+(a.Y&31))|0,b&&c&&a.rd(b,c)}}
function Dc(a){a.Da||Oc(a);if(a.La)a.Id=[];else if(a.Ea&&a.mc)if(!a.Ub||a.bb&32)a.Id=[],a.v.send("screen-clear");else{var b=a.Ac,c=a.Sb;a.Ta&64&&(c>>>=1);var d=a.zc>>5&3,e=Kc(a,b+d);b=e/a.Ea|0;var g=e%a.Ea+c;e=Pc(a,1+a.C);e=Math.min(e,a.Pd);var f=a.Pd-e;a.Id=[];g=-g;for(var h=0;g<a.mc;g+=a.Ea,h++)a.Id.push({Fb:a.Fb,Bf:g,Cf:0,De:0,Ee:b+h,gf:a.Ea,ff:e});b=0;a.Ta&32||(b=Kc(a,d)+c);g=-b;for(h=0;g<a.mc;g+=a.Ea,h++)a.Id.push({Fb:a.Fb,Bf:g,Cf:e,De:0,Ee:h,gf:a.Ea,ff:f})}}
function Fc(a){a.j|=8;a.Ac!==a.Ba&&(a.Ac=a.Ba,Dc(a))}p.xd=function(){this.v.send("screen-update-cursor-scanline",[this.sc,this.qc])};
p.Pi=function(a){if(-1===this.l)this.l=a&31,this.Ub!==(a&32)&&(this.Ub=a&32,Dc(this));else{if(16>this.l)this.Zb[this.l]=a,this.Ta&64||Nc(this);else switch(this.l){case 16:if(this.Ta!==a){var b=this.Ta;this.Ta=a;var c=0<(a&1);this.La||this.Da===c||(this.Da=c,this.v.send("screen-set-mode",this.Da));(b^a)&64&&Mc(this);Lc(this);Nc(this)}break;case 18:this.Cd!==a&&(this.Cd=a,Nc(this));break;case 19:this.Sb!==a&&(this.Sb=a&15,Dc(this));break;case 20:this.Rc!==a&&(this.Rc=a,Nc(this))}this.l=-1}};
p.Ag=function(){return this.l|this.Ub};p.Oi=function(){return this.Ag()&255|this.Bg()<<8&65280};p.Bg=function(){if(16>this.l)return this.Zb[this.l]&255;switch(this.l){case 16:return this.Ta;case 18:return this.Cd;case 19:return this.Sb;case 20:return this.Rc}return 255};p.Qi=function(a){this.$c=a};p.Si=function(a){this.Wb=a};p.Ri=function(){return this.Wb};p.Ui=function(a){switch(this.Wb){case 1:var b=this.bb;this.bb=a;(b^a)&32&&Dc(this);break;case 2:this.Vb=a;break;case 4:this.Xb=a}};
p.Ti=function(){switch(this.Wb){case 1:return this.bb;case 2:return this.Vb;case 4:return this.Xb;case 6:return 18}return 0};p.Wi=function(a){this.X=a};p.Vi=function(){return this.X};p.Yi=function(a){this.tb=3*a;this.pa&=0};p.Xi=function(){return this.pa};p.$i=function(a){this.ba=3*a;this.pa|=3};p.Zi=function(){return this.ba/3&255};
p.bj=function(a){var b=this.ba/3|0,c=this.ba%3,d=this.$a[b];if(0===(this.J&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}d=0===c?d&-16711681|a<<16:1===c?d&-65281|a<<8:d&-256|a;this.$a[b]!==d&&(this.$a[b]=d,Nc(this));this.ba++};p.aj=function(){var a=this.$a[this.tb/3|0]>>8*(2-this.tb%3)&255;this.tb++;return this.J&32?a:a>>2};p.cj=function(){return this.$c};p.ej=function(a){this.Pb=a};p.dj=function(){return this.Pb};
p.gj=function(a){switch(this.Pb){case 0:this.Ob=a;break;case 1:this.wc=a;break;case 2:this.T=a;break;case 3:this.Ra=a;break;case 4:this.xc=a;break;case 5:var b=this.kc;this.kc=a;(b^a)&96&&Mc(this);break;case 6:this.Qa!==a&&(this.Qa=a,Lc(this));break;case 7:this.V=a;break;case 8:this.vc=a}};p.fj=function(){switch(this.Pb){case 0:return this.Ob;case 1:return this.wc;case 2:return this.T;case 3:return this.Ra;case 4:return this.xc;case 5:return this.kc;case 6:return this.Qa;case 7:return this.V;case 8:return this.vc}return 0};
p.ij=function(a){this.F=a};p.hj=function(){return this.F};
p.jj=function(a){switch(this.F){case 1:this.Rb!==a&&(this.Rb=a,Lc(this));break;case 2:this.Qb!==a&&(this.Qb=a,Lc(this));break;case 7:var b=this.i;this.i&=255;this.i=this.i|a<<3&512|a<<7&256;b!=this.i&&Lc(this);this.C=this.C&767|a<<4&256;b=this.g;this.g=this.g&767|a<<5&256;b!==this.g&&Lc(this);Dc(this);break;case 8:this.zc=a;Dc(this);break;case 9:this.Y=a;this.C=this.C&511|a<<3&512;b=this.g;this.g=this.g&511|a<<4&512;b!==this.g&&Lc(this);Dc(this);break;case 10:this.sc=a;this.xd();break;case 11:this.qc=
a;this.xd();break;case 12:(this.Ba>>8&255)!==a&&(this.Ba=this.Ba&255|a<<8,Dc(this),~this.Fa&3&&Mc(this));break;case 13:(this.Ba&255)!==a&&(this.Ba=this.Ba&65280|a,Dc(this),~this.Fa&3&&Mc(this));break;case 14:this.D=this.D&255|a<<8;this.wd();break;case 15:this.D=this.D&65280|a;this.wd();break;case 18:(this.i&255)!==a&&(this.i=this.i&768|a,Lc(this));break;case 19:this.O!==a&&(this.O=a,Lc(this),~this.Fa&3&&Mc(this));break;case 20:this.P!==a&&(b=this.P,this.P=a,Lc(this),(b^a)&64&&Mc(this));break;case 21:(this.g&
255)!==a&&(this.g=this.g&768|a,Lc(this));break;case 23:this.Fa!==a&&(b=this.Fa,this.Fa=a,Lc(this),(b^a)&67&&Mc(this));break;case 24:this.C=this.C&768|a;Dc(this);break;default:this.F<this.cb.length&&(this.cb[this.F]=a)}};
p.Cg=function(){switch(this.F){case 1:return this.Rb;case 2:return this.Qb;case 7:return this.i>>7&2|this.g>>5&8|this.C>>4&16|this.i>>3&64;case 8:return this.zc;case 9:return this.Y;case 10:return this.sc;case 11:return this.qc;case 12:return this.Ba&255;case 13:return this.Ba>>8;case 14:return this.D>>8;case 15:return this.D&255;case 18:return this.i&255;case 19:return this.O;case 20:return this.P;case 21:return this.g&255;case 23:return this.Fa;case 24:return this.C&255}return this.F<this.cb.length?
this.cb[this.F]:0};p.Dg=function(){var a=this.j;this.Da?(this.j^=1,this.j&=1):(this.j&1&&(this.j^=8),this.j^=1);this.l=-1;return a};p.ei=function(a){this.ub=a};
p.gi=function(a){switch(this.ub){case 0:45248<=a&&45253>=a&&(this.ke=a);break;case 1:this.Pa=a;2560<this.Pa&&(this.Pa=2560);break;case 2:this.Za=a;1600<this.Za&&(this.Za=1600);break;case 3:this.Mb=a;break;case 4:this.La=1===(a&1);this.J=a;break;case 5:this.Sa=a<<16;break;case 9:a*=this.Pa,this.ud!==a&&(this.ud=a,Nc(this))}!this.La||this.Pa&&this.Za||(this.La=!1);this.La&&4===this.ub&&(this.qd(this.Pa,this.Za,this.Mb,this.Pa,this.Za),this.v.send("screen-set-mode",!0),this.uc=this.Da=!0);this.La||(this.Sa=
0);Dc(this)};p.fi=function(){return Qc(this,this.ub)};function Qc(a,b){switch(b){case 0:return a.ke;case 1:return a.J&2?2560:a.Pa;case 2:return a.J&2?1600:a.Za;case 3:return a.J&2?32:a.Mb;case 4:return a.J;case 5:return a.Sa>>>16;case 6:return a.mc?a.mc:1;case 8:return 0;case 10:return a.ha/65536|0}return 255};function Rc(a,b){this.s=a;this.v=b;this.yd=this.tc=!1;this.ie=!0;this.dd=this.Ib=this.Hb=0;this.pa=!0;this.P=this.O=this.F=this.L=this.T=this.J=this.ce=!1;this.ja=new Ab(1024);this.l=0;this.Jc=100;this.j=this.i=0;this.C=!1;this.Nb=0;this.Md=4;this.B=!1;this.g=new Ab(1024);this.D=this.o=!1;this.v.register("keyboard-code",function(c){this.ce&&(this.ja.push(c),this.Aa())},this);this.v.register("mouse-click",function(c){this.ie&&this.yd&&(this.dd=c[0]|c[2]<<1|c[1]<<2,this.tc&&Sc(this,0,0))},this);this.v.register("mouse-delta",
function(c){var d=c[1];if(this.ie&&this.yd){var e=this.Md*this.Jc/80;this.Hb+=c[0]*e;this.Ib+=d*e;this.tc&&(c=this.Hb|0,d=this.Ib|0,c||d)&&(this.Hb-=c,this.Ib-=d,Sc(this,c,d))}},this);this.v.register("mouse-wheel",function(c){this.Nb-=c[0];this.Nb-=2*c[1];this.Nb=Math.min(7,Math.max(-8,this.Nb));Sc(this,0,0)},this);this.h=5;this.ba=0;this.X=this.V=this.Y=!1;K(a.A,96,this,this.xj);K(a.A,100,this,this.zj);L(a.A,96,this,this.yj);L(a.A,100,this,this.Aj)}p=Rc.prototype;
p.$=function(){var a=[];a[0]=this.tc;a[1]=this.yd;a[2]=this.ie;a[3]=this.Hb;a[4]=this.Ib;a[5]=this.dd;a[6]=this.pa;a[7]=this.ce;a[8]=this.J;a[9]=this.T;a[10]=this.L;a[11]=this.F;a[12]=this.O;a[13]=this.P;a[15]=this.l;a[16]=this.Jc;a[17]=this.Md;a[18]=this.B;a[20]=this.h;a[21]=this.Y;a[22]=this.V;a[23]=this.ba;a[24]=this.X;a[25]=this.j;a[26]=this.i;a[27]=this.C;return a};
p.H=function(a){this.tc=a[0];this.yd=a[1];this.ie=a[2];this.Hb=a[3];this.Ib=a[4];this.dd=a[5];this.pa=a[6];this.ce=a[7];this.J=a[8];this.T=a[9];this.L=a[10];this.F=a[11];this.O=a[12];this.P=a[13];this.l=a[15];this.Jc=a[16];this.Md=a[17];this.B=a[18];this.h=a[20];this.Y=a[21];this.V=a[22];this.ba=a[23];this.X=a[24];this.j=a[25]||0;this.i=a[26]||0;this.C=a[27]||!1;this.D=this.o=!1;this.ja.clear();this.g.clear();this.v.send("mouse-enable",this.yd)};
p.Aa=function(){this.o||(this.ja.length?Tc(this):this.g.length&&Uc(this))};function Uc(a){a.o=!0;a.D=!0;a.h&2&&(Jb(a.s,12),a.s.Ka(12))}function Tc(a){a.o=!0;a.D=!1;a.h&1&&(Jb(a.s,1),a.s.Ka(1))}function Sc(a,b,c){a.g.push((0>c)<<5|(0>b)<<4|8|a.dd);a.g.push(b);a.g.push(c);4===a.j?(a.g.push(0|a.Nb&15),a.Nb=0):3===a.j&&(a.g.push(a.Nb&255),a.Nb=0);a.Aa()}
p.xj=function(){this.o=!1;if(!this.ja.length&&!this.g.length)return this.l;this.D?(Jb(this.s,12),this.l=this.g.shift()):(Jb(this.s,1),this.l=this.ja.shift());(this.ja.length||this.g.length)&&this.Aa();return this.l};p.zj=function(){var a=16;this.o&&(a|=1);this.D&&(a|=32);return a};
p.yj=function(a){if(this.V)this.h=a,this.V=!1;else if(this.Y)this.Y=!1,this.g.clear(),this.g.push(a),Uc(this);else if(this.T){this.T=!1;this.g.clear();this.g.push(250);this.Jc=a;switch(this.i){case -1:60===a?(this.C=!0,this.i=0):(this.C=!1,this.i=200===a?1:0);break;case 0:200===a&&(this.i=1);break;case 1:this.i=100===a?2:200===a?3:0;break;case 2:80===a&&(this.j=3);this.i=-1;break;case 3:80===a&&(this.j=4),this.i=-1}this.Jc||(this.Jc=100);Uc(this)}else if(this.P)this.P=!1,this.g.clear(),this.g.push(250),
this.Md=3<a?4:1<<a,Uc(this);else if(this.L)this.L=!1,this.ja.push(250),Tc(this);else if(this.F)this.F=!1,this.ja.push(250),Tc(this),a||this.ja.push(2);else if(this.O)this.O=!1,this.ja.push(250),Tc(this);else if(this.J){if(this.J=!1,this.ie){this.ja.clear();this.g.clear();this.g.push(250);switch(a){case 230:this.B=!1;break;case 231:this.B=!0;break;case 232:this.P=!0;break;case 233:Sc(this,0,0);break;case 235:Sc(this,0,0);break;case 242:this.g.push(this.j);this.dd=this.Hb=this.Ib=0;this.Aa();break;
case 243:this.T=!0;break;case 244:this.yd=this.tc=!0;this.v.send("mouse-enable",!0);this.dd=this.Hb=this.Ib=0;break;case 245:this.tc=!1;break;case 246:this.tc=!1;this.Jc=100;this.B=!1;this.Md=4;break;case 255:this.g.push(170),this.g.push(0),this.yd=!0,this.v.send("mouse-enable",!0),this.tc=!1,this.Jc=100,this.B=!1,this.Md=4,this.C||(this.j=0),this.dd=this.Hb=this.Ib=0}Uc(this)}}else if(this.X)this.X=!1,this.ba=a;else{this.g.clear();this.ja.clear();this.ja.push(250);switch(a){case 237:this.L=!0;break;
case 240:this.F=!0;break;case 242:this.ja.push(171);this.ja.push(83);break;case 243:this.O=!0;break;case 244:this.ce=!0;break;case 245:this.ce=!1;break;case 255:this.ja.clear(),this.ja.push(250),this.ja.push(170),this.ja.push(0)}Tc(this)}};
p.Aj=function(a){switch(a){case 32:this.ja.clear();this.g.clear();this.ja.push(this.h);Tc(this);break;case 96:this.V=!0;break;case 209:this.X=!0;break;case 211:this.Y=!0;break;case 212:this.J=!0;break;case 167:this.h|=32;break;case 168:this.h&=-33;break;case 169:this.ja.clear();this.g.clear();this.ja.push(0);Tc(this);break;case 170:this.ja.clear();this.g.clear();this.ja.push(85);Tc(this);break;case 171:this.ja.clear();this.g.clear();this.ja.push(0);Tc(this);break;case 173:this.h|=16;break;case 174:this.h&=
-17;break;case 254:lc(this.s)}};function Vc(a,b){this.h=this.g=this.R=this.C=this.l=0;this.i=-1;this.ka=b;this.D=void 0===this.ka;this.la=void 0;this.name=this.D?"master":"slave ";this.F=!1;this.J=this.state=0;this.o=1;this.B=this.L=0;this.s=a;this.D?(this.la=new Vc(this.s,this),this.j=function(){if(0<=this.i)pb(this.s);else{var c=this.g&this.l;if(c){c&=-c;var d=this.L?this.l:-1;this.R&&(this.R&-this.R&d)<=c||(this.i=rb(c),pb(this.s))}}},this.Vd=function(){if(-1!==this.i)if(0===this.g)this.i=-1;else{var c=1<<this.i;0===(this.B&
c)&&(this.g&=~c);this.o||(this.R|=c);2===this.i?this.la.Vd():this.s.C(this.C|this.i);this.i=-1;this.j()}}):(this.j=function(){if(0<=this.i)pb(this.s);else{var c=this.g&this.l;if(c){c&=-c;var d=this.L?this.l:-1;this.R&&(this.R&-this.R&d)<=c||(this.i=rb(c),this.ka.Rd(2))}}},this.Vd=function(){if(-1!==this.i)if(0===this.g)this.i=-1,this.ka.h&=-5,this.s.C(this.C|7);else{var c=1<<this.i;0===(this.B&c)&&(this.g&=~c);this.o||(this.R|=c);this.ka.h&=-5;this.s.C(this.C|this.i);this.i=-1;this.j()}});this.D?
(a=32,b=1232):(a=160,b=1233);L(this.s.A,a,this,this.ii);K(this.s.A,a,this,this.hi);L(this.s.A,a|1,this,this.ki);K(this.s.A,a|1,this,this.ji);L(this.s.A,b,this,this.wj);K(this.s.A,b,this,this.vj);this.D?(this.Rd=function(c){8<=c?this.la.Rd(c-8):(c=1<<c,0===(this.h&c)&&(this.g|=c,this.h|=c,this.j()))},this.Wd=function(c){8<=c?this.la.Wd(c-8):(c=1<<c,this.h&c&&(this.h&=~c,this.g&=~c,this.j()))}):(this.Rd=function(c){c=1<<c;0===(this.h&c)&&(this.g|=c,this.h|=c,this.j())},this.Wd=function(c){c=1<<c;this.h&
c&&(this.h&=~c,this.g&=~c,this.j())})}p=Vc.prototype;p.$=function(){var a=[];a[0]=this.l;a[1]=this.C;a[2]=this.R;a[3]=this.g;a[4]=this.D;a[5]=this.la;a[6]=this.F;a[7]=this.state;a[8]=this.J;a[9]=this.o;a[10]=this.B;return a};p.H=function(a){this.l=a[0];this.C=a[1];this.R=a[2];this.g=a[3];this.D=a[4];this.la&&this.la.H(a[5]);this.F=a[6];this.state=a[7];this.J=a[8];this.o=a[9];this.B=a[10]};
p.ii=function(a){if(a&16)this.h=this.l=this.g=this.R=0,this.o=1,this.i=-1,this.F=a&1,this.state=1;else if(a&8)a&2&&(this.J=a&1),a&64&&(this.L=32===(a&32));else{var b=a>>5;1===b?this.R&=this.R-1:3===b?this.R&=~(1<<(a&7)):192!==(a&200)&&(this.R&=this.R-1);this.j()}};p.hi=function(){return this.J?this.R:this.g};p.ki=function(a){0===this.state?this.F?(this.F=!1,this.o=a&2):(this.l=~a,this.j()):1===this.state?(this.C=a,this.state++):2===this.state&&(this.state=0)};p.ji=function(){return~this.l&255};
p.vj=function(){return this.B};p.wj=function(a){this.B=a};function Wc(a){this.s=a;this.Qc=0;this.W=new Uint8Array(128);this.D=this.g=Date.now();this.l=this.j=0;this.B=!1;this.C=.9765625;this.o=38;this.h=2;this.tf=this.i=0;L(a.A,112,this,function(b){this.Qc=b&127;this.tf=b>>7});L(a.A,113,this,this.ph);K(a.A,113,this,this.oh)}p=Wc.prototype;p.$=function(){var a=[];a[0]=this.Qc;a[1]=this.W;a[2]=this.g;a[3]=this.D;a[4]=this.j;a[5]=this.l;a[6]=this.B;a[7]=this.C;a[8]=this.o;a[9]=this.h;a[10]=this.i;a[11]=this.tf;return a};
p.H=function(a){this.Qc=a[0];this.W=a[1];this.g=a[2];this.D=a[3];this.j=a[4];this.l=a[5];this.B=a[6];this.C=a[7];this.o=a[8];this.h=a[9];this.i=a[10];this.tf=a[11]};p.sb=function(a){a=Date.now();this.g+=a-this.D;this.D=a;this.B&&this.j<a?(this.s.Ka(8),this.i|=192,this.j+=this.C*Math.ceil((a-this.j)/this.C)):this.l&&this.l<a&&(this.s.Ka(8),this.i|=160,this.l=0);let b=100;this.B&&this.j&&(b=Math.min(b,Math.max(0,this.j-a)));this.l&&(b=Math.min(b,Math.max(0,this.l-a)));return b};
function Xc(a,b){if(a.h&4)a=b;else{a=b;for(var c=b=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;a=c}return a}function Yc(a,b){var c;a.h&4?c=b:c=(b&15)+10*(b>>4&15);return c}
p.oh=function(){switch(this.Qc){case 0:return Xc(this,(new Date(this.g)).getUTCSeconds());case 2:return Xc(this,(new Date(this.g)).getUTCMinutes());case 4:return Xc(this,(new Date(this.g)).getUTCHours());case 7:return Xc(this,(new Date(this.g)).getUTCDate());case 8:return Xc(this,(new Date(this.g)).getUTCMonth()+1);case 9:return Xc(this,(new Date(this.g)).getUTCFullYear()%100);case 10:return 999<=nb()%1E3?this.o|128:this.o;case 11:return this.h;case 12:Jb(this.s,8);var a=this.i;this.i&=-241;return a;
case 13:return 0;case 50:return Xc(this,(new Date(this.g)).getUTCFullYear()/100|0);default:return this.W[this.Qc]}};
p.ph=function(a){switch(this.Qc){case 10:this.o=a&127;this.C=1E3/(32768>>(this.o&15)-1);break;case 11:this.h=a;this.h&64&&(this.j=Date.now());if(this.h&32){a=new Date;const b=Yc(this,this.W[1]),c=Yc(this,this.W[3]),d=Yc(this,this.W[5]);this.l=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b))}break;case 1:case 3:case 5:this.W[this.Qc]=a}this.B=64===(this.h&64)&&0<(this.o&15)};function Zc(a,b,c){this.v=c;this.s=a;this.g=4;this.Bc=this.nc=0;this.cd=96;this.ec=this.ee=0;this.fc=1;this.ca=this.$e=this.rf=this.Re=0;this.input=new Ab(4096);switch(b){case 1016:this.h=0;this.ca=4;break;case 760:this.h=1;this.ca=3;break;case 1E3:this.h=2;this.ca=4;break;case 744:this.ca=this.h=3;break;default:this.h=0,this.ca=4}this.v.register("serial"+this.h+"-input",function(d){this.input.push(d);this.cd|=1;this.ee&1?$c(this,12):$c(this,4)},this);a=a.A;L(a,b,this,function(d){ad(this,d)},function(d){ad(this,
d&255);ad(this,d>>8)});L(a,b|1,this,function(d){this.Bc&128?this.nc=this.nc&255|d<<8:(0===(this.ec&2)&&d&2&&$c(this,2),this.ec=d&15,bd(this))});K(a,b,this,function(){if(this.Bc&128)return this.nc&255;var d=this.input.shift();0===this.input.length&&(this.cd&=-2,cd(this,12),cd(this,4));return d});K(a,b|1,this,function(){return this.Bc&128?this.nc>>8:this.ec&15});K(a,b|2,this,function(){var d=this.fc&15;2==this.fc&&cd(this,2);this.ee&1&&(d|=192);return d});L(a,b|2,this,function(d){this.ee=d});K(a,b|
3,this,function(){return this.Bc});L(a,b|3,this,function(d){this.Bc=d});K(a,b|4,this,function(){return this.Re});L(a,b|4,this,function(d){this.Re=d});K(a,b|5,this,function(){return this.cd});L(a,b|5,this,function(){});K(a,b|6,this,function(){return this.rf});L(a,b|6,this,function(){});K(a,b|7,this,function(){return this.$e});L(a,b|7,this,function(d){this.$e=d})}
Zc.prototype.$=function(){var a=[];a[0]=this.g;a[1]=this.nc;a[2]=this.Bc;a[3]=this.cd;a[4]=this.ee;a[5]=this.ec;a[6]=this.fc;a[7]=this.Re;a[8]=this.rf;a[9]=this.$e;a[10]=this.ca;return a};Zc.prototype.H=function(a){this.g=a[0];this.nc=a[1];this.Bc=a[2];this.cd=a[3];this.ee=a[4];this.ec=a[5];this.fc=a[6];this.Re=a[7];this.rf=a[8];this.$e=a[9];this.ca=a[10]};
function bd(a){a.g&4096&&a.ec&1?(a.fc=12,a.s.Ka(a.ca)):a.g&16&&a.ec&1?(a.fc=4,a.s.Ka(a.ca)):a.g&4&&a.ec&2?(a.fc=2,a.s.Ka(a.ca)):a.g&1&&a.ec&8?(a.fc=0,a.s.Ka(a.ca)):(a.fc=1,Jb(a.s,a.ca))}function $c(a,b){a.g|=1<<b;bd(a)}function cd(a,b){a.g&=~(1<<b);bd(a)}function ad(a,b){a.Bc&128?a.nc=a.nc&-256|b:($c(a,2),255!==b&&a.v.send("serial"+a.h+"-output-char",String.fromCharCode(b)))};function dd(a){this.s=a;var b=a.A;Tb(a.u.Ha,{Ia:56,K:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],ib:[],name:"acpi"});this.g=this.h=0;this.status=1;this.ne=this.kd=0;this.i=ed(this,nb());this.Eb=new Uint8Array(4);K(b,45056,this,void 0,function(){return this.kd});L(b,45056,this,void 0,function(c){this.kd&=~c});K(b,45058,this,void 0,function(){return this.ne});L(b,45058,this,void 0,function(c){this.ne=
c});K(b,45060,this,void 0,function(){return this.status});L(b,45060,this,void 0,function(c){this.status=c});K(b,45064,this,void 0,void 0,function(){return ed(this,nb())&16777215});K(b,45024,this,function(){return this.Eb[0]});K(b,45025,this,function(){return this.Eb[1]});K(b,45026,this,function(){return this.Eb[2]});K(b,45027,this,function(){return this.Eb[3]});L(b,45024,this,function(c){this.Eb[0]=c});L(b,45025,this,function(c){this.Eb[1]=c});L(b,45026,this,function(c){this.Eb[2]=c});L(b,45027,this,
function(c){this.Eb[3]=c})}dd.prototype.sb=function(a){a=ed(this,a);var b=0!==((a^this.i)&8388608);this.ne&1&&b?(this.kd|=1,this.s.Ka(9)):Jb(this.s,9);this.i=a;return 100};function ed(a,b){b=Math.round(3579.545*b);b===a.h?3579.545>a.g&&a.g++:a.h+a.g<=b&&(a.g=0,a.h=b);return a.h+a.g}dd.prototype.$=function(){var a=[];a[0]=this.status;a[1]=this.kd;a[2]=this.ne;a[3]=this.Eb;return a};dd.prototype.H=function(a){this.status=a[0];this.kd=a[1];this.ne=a[2];this.Eb=a[3]};function fd(a){this.s=a;this.Y=this.pa=0;this.ba=1;this.g=this.l=0;this.j=nb();this.L=this.P=this.O=this.T=this.h=65536;this.F=this.D=this.B=0;this.i=new Int32Array(8);this.R=new Int32Array(8);this.o=new Int32Array(8);this.X=254;this.C=-1;this.V=this.error=this.J=0;hb(a.A,4276092928,1048576,b=>{var c=b&3;return this.qe(b&-4)>>8*c&255},()=>{},b=>this.qe(b),(b,c)=>this.Lc(b,c))}p=fd.prototype;
p.qe=function(a){a=a-4276092928|0;switch(a){case 32:return this.pa;case 48:return 327700;case 128:return this.B;case 208:return this.J;case 224:return this.C;case 240:return this.X;case 256:case 272:case 288:case 304:case 320:case 336:case 352:case 368:return this.R[a-256>>4];case 384:case 400:case 416:case 432:case 448:case 464:case 480:case 496:return this.o[a-384>>4];case 512:case 528:case 544:case 560:case 576:case 592:case 608:case 624:return this.i[a-512>>4];case 640:return this.V;case 768:return this.D;
case 784:return this.F;case 800:return this.h;case 832:return this.T;case 848:return this.O;case 864:return this.P;case 880:return this.L;case 992:return this.Y;case 896:return this.l;case 912:return this.g;default:return 0}};
p.Lc=function(a,b){switch(a-4276092928|0){case 128:this.B=b&255;gd(this);break;case 176:b=hd(this.R);if(-1!==b){id(this.R,b);if(this.o[b>>5]>>(b&31)&1){a=this.s.u.yc;for(var c=0;24>c;c++){var d=a.g[c];(d&255)===b&&d&16384&&(a.g[c]&=-16385,jd(a,c))}}gd(this)}break;case 208:this.J=b&4278190080;break;case 224:this.C=b|16777215;break;case 240:this.X=b;break;case 640:this.V=this.error;this.error=0;break;case 768:a=b&255;c=b>>8&7;d=b>>15&1;var e=b>>18&3;this.D=b&-4097;0===e?kd(this,a,c,d):1===e?kd(this,
a,0,d):2===e&&kd(this,a,c,d);break;case 784:this.F=b;break;case 800:this.h=b;break;case 832:this.T=b;break;case 848:this.O=b;break;case 864:this.P=b;break;case 880:this.L=b;break;case 992:this.Y=b;b=b&3|(b&8)>>1;this.ba=7===b?0:b+1;break;case 896:this.l=b>>>0,this.g=b>>>0,this.j=nb()}};
p.sb=function(a){if(0===this.g)return 100;const b=1E6/(1<<this.ba);a=(a-this.j)*b>>>0;this.j+=a/b;this.g-=a;0>=this.g&&(a=this.h&393216,131072===a?(this.g%=this.l,0>=this.g&&(this.g+=this.l),0===(this.h&65536)&&kd(this,this.h&255,0,!1)):0===a&&(this.g=0,0===(this.h&65536)&&kd(this,this.h&255,0,!1)));return Math.max(0,this.g/b)};function kd(a,b,c,d){5===c||4===c||a.i[b>>5]>>(b&31)&1||(ld(a.i,b),d?ld(a.o,b):id(a.o,b),gd(a))}
function gd(a){var b=hd(a.i);-1!==b&&(hd(a.R)>=b||(b&240)<=(a.B&240)||pb(a.s))}p.Vd=function(){var a=hd(this.i);-1===a||hd(this.R)>=a||(a&240)<=(this.B&240)||(id(this.i,a),ld(this.R,a),this.s.C(a),gd(this))};
p.$=function(){var a=[];a[0]=this.pa;a[1]=this.Y;a[2]=this.ba;a[3]=this.l;a[4]=this.g;a[5]=this.j;a[6]=this.h;a[7]=this.T;a[8]=this.O;a[9]=this.P;a[10]=this.L;a[11]=this.B;a[12]=this.D;a[13]=this.F;a[14]=this.i;a[15]=this.R;a[16]=this.o;a[17]=this.X;a[18]=this.C;a[19]=this.J;a[20]=this.error;a[21]=this.V;return a};
p.H=function(a){this.pa=a[0];this.Y=a[1];this.ba=a[2];this.l=a[3];this.g=a[4];this.j=a[5];this.h=a[6];this.T=a[7];this.O=a[8];this.P=a[9];this.L=a[10];this.B=a[11];this.D=a[12];this.F=a[13];this.i=a[14];this.R=a[15];this.o=a[16];this.X=a[17];this.C=a[18];this.J=a[19];this.error=a[20];this.V=a[21]};function ld(a,b){a[b>>5]|=1<<(b&31)}function id(a,b){a[b>>5]&=~(1<<(b&31))}function hd(a){for(var b=7;0<=b;b--){var c=a[b];if(c)return sb(c>>>0)|b<<5}return-1};function md(a){this.s=a;this.g=new Int32Array(24);this.o=new Int32Array(24);for(var b=0;b<this.g.length;b++)this.g[b]=65536;this.i=this.h=this.l=this.j=0;hb(a.A,4273995776,131072,c=>{c=c-4273995776|0;return 16<=c&&20>c?(c-=16,this.read(this.j)>>8*c&255):0},()=>{},c=>{c=c-4273995776|0;return 0===c?this.j:16===c?this.read(this.j):0},(c,d)=>{c=c-4273995776|0;0===c?this.j=d:16===c&&this.write(this.j,d)})}
function jd(a,b){var c=1<<b;if(0!==(a.h&c)){var d=a.g[b];if(0===(d&65536)){var e=d>>8&7;if(0===(d&32768))a.h&=~c;else if(a.g[b]|=16384,d&16384)return;0!==e&&1!==e||kd(a.s.u.Mc,d&255,e,32768===(d&32768));a.g[b]&=-4097}}}p=md.prototype;p.Rd=function(a){if(!(24<=a)){var b=1<<a;0===(this.i&b)&&(this.i|=b,65536!==(this.g[a]&98304)&&(this.h|=b,jd(this,a)))}};p.Wd=function(a){if(!(24<=a)){var b=1<<a;(this.i&b)===b&&(this.i&=~b,this.g[a]&32768&&(this.h&=~b))}};
p.read=function(a){if(0===a)return this.l<<24;if(1===a)return 1507345;if(2===a)return this.l<<24;if(16<=a&&64>a){var b=a-16>>1;return a&1?this.o[b]:this.g[b]}return 0};p.write=function(a,b){if(0===a)this.l=b>>>24&15;else if(1!==a&&2!==a&&16<=a&&64>a){var c=a-16>>1;a&1?this.o[c]=b&4278190080:(this.g[c]=b&110591|this.g[c]&-110592,jd(this,c))}};p.$=function(){var a=[];a[0]=this.g;a[1]=this.o;a[2]=this.j;a[3]=this.l;a[4]=this.h;a[5]=this.i;return a};
p.H=function(a){this.g=a[0];this.o=a[1];this.j=a[2];this.l=a[3];this.h=a[4];this.i=a[5]};function nd(a){this.message=a}nd.prototype=Error();const od={Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};
function pd(a,b){if("object"!==typeof a||null===a)return a;if(a instanceof Array)return a.map(e=>pd(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.$();c=[];for(var d=0;d<a.length;d++)c[d]=pd(a[d],b);return c}
function qd(a,b){if("object"!==typeof a||null===a)return a;if(a instanceof Array){for(let c=0;c<a.length;c++)a[c]=qd(a[c],b);return a}return new od[a.__state_type__](b[a.buffer_id])}
jb.prototype.se=function(){for(var a=[],b=pd(this,a),c=[],d=0,e=0;e<a.length;e++){var g=a[e].byteLength;c[e]={offset:d,length:g};d+=g;d=d+3&-4}e=JSON.stringify({buffer_infos:c,state:b});e=(new TextEncoder).encode(e);b=16+e.length;b=b+3&-4;g=b+d;d=new ArrayBuffer(g);var f=new Int32Array(d,0,4);(new Uint8Array(d,16,e.length)).set(e);b=new Uint8Array(d,b);f[0]=-2039052682;f[1]=6;f[2]=g;f[3]=e.length;for(e=0;e<a.length;e++)b.set(a[e],c[e].offset);return d};
jb.prototype.Nd=function(a){function b(n,t){const m=n.length;if(16>m)throw new nd("Invalid length: "+m);n=new Int32Array(n.buffer,n.byteOffset,4);if(-2039052682!==n[0])throw new nd("Invalid header: "+yb(n[0]>>>0));if(6!==n[1])throw new nd("Version mismatch: dump="+n[1]+" we=6");if(t&&n[2]!==m)throw new nd("Length doesn't match header: real="+m+" header="+n[2]);return n[3]}function c(n){n=(new TextDecoder).decode(n);return JSON.parse(n)}a=new Uint8Array(a);if(4247762216===(new Uint32Array(a.buffer,
0,1))[0]){var d=this.Tg(a.length);(new Uint8Array(this.Ja.buffer,this.Vg(d),a.length)).set(a);var e=this.Td(d,16),g=new Uint8Array(this.Ja.buffer,e,16),f=b(g,!1);this.Ud(e,16);e=this.Td(d,f);g=new Uint8Array(this.Ja.buffer,e,f);g=c(g);this.Ud(e,f);e=g.state;var h=g.buffer_infos;g=[];f=16+f;for(var k of h){h=(f+3&-4)-f;if(1048576<k.length){var l=this.Td(d,h);this.Ud(l,h);l=new Uint8Array(k.length);g.push(l.buffer);for(var q=0;q<k.length;){const n=Math.min(k.length-q,1048576),t=this.Td(d,n);l.set(new Uint8Array(this.Ja.buffer,
t,n),q);this.Ud(t,n);q+=n}}else l=this.Td(d,h+k.length),q=l+h,g.push(this.Ja.buffer.slice(q,q+k.length)),this.Ud(l,h+k.length);f+=h+k.length}e=qd(e,g);this.H(e);this.Ug(d)}else{k=b(a,!0);if(0>k||k+12>=a.length)throw new nd("Invalid info block length: "+k);e=c(a.subarray(16,16+k));d=e.state;e=e.buffer_infos;let n=16+k;n=n+3&-4;k=e.map(t=>{const m=n+t.offset;return a.buffer.slice(m,m+t.length)});d=qd(d,k);this.H(d)}};function rd(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d){if(a=a.subarray(14),4===a[0]>>4&&17===a[9]&&(a=a.subarray(20),d=a[2]<<8|a[3],67===(a[0]<<8|a[1])||67===d)){const e=a.subarray(8);if(1669485411===(e[236]<<24|e[237]<<
16|e[238]<<8|e[239]))for(e[28]===b[0]&&e[29]===b[1]&&e[30]===b[2]&&e[31]===b[3]&&e[32]===b[4]&&e[33]===b[5]&&(e[28]=c[0],e[29]=c[1],e[30]=c[2],e[31]=c[3],e[32]=c[4],e[33]=c[5],a[6]=a[7]=0),d=240;d<e.length;){const g=e[d++];if(255===g)break;const f=e[d++];61===g&&1===e[d+0]&&e[d+1]===b[0]&&e[d+2]===b[1]&&e[d+3]===b[2]&&e[d+4]===b[3]&&e[d+5]===b[4]&&e[d+6]===b[5]&&(e[d+1]=c[0],e[d+2]=c[1],e[d+3]=c[2],e[d+4]=c[3],e[d+5]=c[4],e[d+6]=c[5],a[6]=a[7]=0);d+=f}}}else 2054===d&&(a=a.subarray(14),a[8]===b[0]&&
a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}
function sd(a,b,c,d){this.s=a;this.Ha=a.u.Ha;this.vf=c;this.Gb=d;this.v=b;this.v.register("net0-receive",function(e){if(!(this.Ma&1)&&(this.v.send("eth-receive-end",[e.length]),this.Od&16||this.Od&4&&255===e[0]&&255===e[1]&&255===e[2]&&255===e[3]&&255===e[4]&&255===e[5]||!(this.Od&8&&1===(e[0]&1)||e[0]!==this.sa[0]||e[1]!==this.sa[1]||e[2]!==this.sa[2]||e[3]!==this.sa[3]||e[4]!==this.sa[4]||e[5]!==this.sa[5]))){this.le&&(e=new Uint8Array(e),rd(e,this.sa,this.le));var g=this.wb<<8,f=Math.max(60,e.length)+
4,h=g+4,k=this.wb+1+(f>>8);if(!((this.pc>this.wb?this.pc-this.wb:this.Va-this.wb+this.pc-this.Kb)<1+(f>>8)&&0!==this.pc)){if(g+f>this.Va<<8){var l=(this.Va<<8)-h;this.memory.set(e.subarray(0,l),h);this.memory.set(e.subarray(l),this.Kb<<8)}else this.memory.set(e,h),60>e.length&&this.memory.fill(0,h+e.length,h+60);k>=this.Va&&(k+=this.Kb-this.Va);this.memory[g]=1;this.memory[g+1]=k;this.memory[g+2]=f;this.memory[g+3]=f>>8;this.wb=k;td(this,1)}}},this);this.port=768;this.name="ne2k";this.K=[236,16,41,
128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.Ia=40;this.ib=[{size:32}];this.Le=this.R=0;this.Ma=1;this.bf=this.vd=this.rb=this.Xd=0;this.memory=new Uint8Array(32768);this.If=this.Od=0;this.Hf=1;this.sa=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.le=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.sa[b];this.memory[28]=this.memory[29]=
87;this.memory[30]=this.memory[31]=87;this.ua=0;this.Kb=64;this.Va=128;this.pc=this.wb=76;b=a.A;K(b,this.port|0,this,function(){return this.Ma});L(b,this.port|0,this,function(e){this.Ma=e;this.Ma&1||(e&24&&0===this.rb&&td(this,64),e&4&&(e=this.bf<<8,e=this.memory.subarray(e,e+this.vd),this.le&&(e=new Uint8Array(e),rd(e,this.le,this.sa)),this.v.send("net0-send",e),this.v.send("eth-transmit-end",[e.length]),this.Ma&=-5,td(this,2)))});K(b,this.port|13,this,function(){return 0});K(b,this.port|14,this,
function(){return 0},function(){return 0});K(b,this.port|15,this,function(){return 0});K(b,this.port|31,this,function(){td(this,128);return 0});L(b,this.port|31,this,function(){});K(b,this.port|1,this,function(){var e=S(this);return 0===e?this.Kb:1===e?this.sa[0]:2===e?this.Kb:0});L(b,this.port|1,this,function(e){var g=S(this);0===g?this.Kb=e:1===g&&(this.sa[0]=e)});K(b,this.port|2,this,function(){var e=S(this);return 0===e?this.Va:1===e?this.sa[1]:2===e?this.Va:0});L(b,this.port|2,this,function(e){var g=
S(this);0===g?(e>this.memory.length>>8&&(e=this.memory.length>>8),this.Va=e):1===g&&(this.sa[1]=e)});K(b,this.port|7,this,function(){var e=S(this);if(0===e)return this.R;if(1===e)return this.wb});L(b,this.port|7,this,function(e){var g=S(this);0===g?(this.R&=~e,ud(this)):1===g&&(this.wb=e)});L(b,this.port|13,this,function(e){0===S(this)&&(this.If=e)});L(b,this.port|14,this,function(e){0===S(this)&&(this.Xd=e)});K(b,this.port|10,this,function(){return 0===S(this)?80:0});L(b,this.port|10,this,function(e){0===
S(this)&&(this.rb=this.rb&65280|e&255)});K(b,this.port|11,this,function(){return 0===S(this)?67:0});L(b,this.port|11,this,function(e){0===S(this)&&(this.rb=this.rb&255|e<<8&65280)});K(b,this.port|8,this,function(){if(0===S(this))return this.ua&255});L(b,this.port|8,this,function(e){0===S(this)&&(this.ua=this.ua&65280|e&255)});K(b,this.port|9,this,function(){if(0===S(this))return this.ua>>8&255});L(b,this.port|9,this,function(e){0===S(this)&&(this.ua=this.ua&255|e<<8&65280)});L(b,this.port|15,this,
function(e){0===S(this)&&(this.Le=e,ud(this))});K(b,this.port|3,this,function(){var e=S(this);return 0===e?this.pc:1===e?this.sa[2]:0});L(b,this.port|3,this,function(e){var g=S(this);0===g?this.pc=e:1===g&&(this.sa[2]=e)});K(b,this.port|4,this,function(){var e=S(this);return 0===e?this.Hf:1===e?this.sa[3]:0});L(b,this.port|4,this,function(e){var g=S(this);0===g?this.bf=e:1===g&&(this.sa[3]=e)});K(b,this.port|5,this,function(){var e=S(this);return 0===e?0:1===e?this.sa[4]:0});L(b,this.port|5,this,
function(e){var g=S(this);0===g?this.vd=this.vd&-256|e:1===g&&(this.sa[4]=e)});K(b,this.port|6,this,function(){var e=S(this);return 0===e?0:1===e?this.sa[5]:0});L(b,this.port|6,this,function(e){var g=S(this);0===g?this.vd=this.vd&255|e<<8:1===g&&(this.sa[5]=e)});K(b,this.port|12,this,function(){return 0===S(this)?9:0});L(b,this.port|12,this,function(e){0===S(this)&&(this.Od=e)});K(b,this.port|16,this,this.sh,this.Tf,this.rh);L(b,this.port|16,this,this.Uf,this.Uf,this.th);Tb(a.u.Ha,this)}p=sd.prototype;
p.$=function(){var a=[];a[0]=this.R;a[1]=this.Le;a[2]=this.Ma;a[3]=this.Xd;a[4]=this.rb;a[5]=this.vd;a[6]=this.bf;a[7]=this.ua;a[8]=this.Kb;a[9]=this.wb;a[10]=this.pc;a[11]=this.Va;a[12]=this.Od;a[13]=this.If;a[14]=this.Hf;a[15]=this.sa;a[16]=this.memory;return a};
p.H=function(a){this.R=a[0];this.Le=a[1];this.Ma=a[2];this.Xd=a[3];this.rb=a[4];this.vd=a[5];this.bf=a[6];this.ua=a[7];this.Kb=a[8];this.wb=a[9];this.pc=a[10];this.Va=a[11];this.Od=a[12];this.If=a[13];this.Hf=a[14];this.vf?(this.sa=a[15],this.memory=a[16]):this.Gb&&(this.le=a[15],this.memory=a[16])};function td(a,b){a.R|=b;ud(a)}function ud(a){a.Le&a.R?a.Ha.Aa(a.Ia):mc(a.Ha,a.Ia)}
function vd(a,b){if(16>=a.ua||16384<=a.ua&&32768>a.ua)a.memory[a.ua]=b;a.ua++;a.rb--;a.ua>=a.Va<<8&&(a.ua+=a.Kb-a.Va<<8);0===a.rb&&td(a,64)}p.Uf=function(a){vd(this,a);this.Xd&1&&vd(this,a>>8)};p.th=function(a){vd(this,a);vd(this,a>>8);vd(this,a>>16);vd(this,a>>24)};function wd(a){let b=0;32768>a.ua&&(b=a.memory[a.ua]);a.ua++;a.rb--;a.ua>=a.Va<<8&&(a.ua+=a.Kb-a.Va<<8);0===a.rb&&td(a,64);return b}p.sh=function(){return this.Tf()&255};p.Tf=function(){return this.Xd&1?wd(this)|wd(this)<<8:wd(this)};
p.rh=function(){return wd(this)|wd(this)<<8|wd(this)<<16|wd(this)<<24};function S(a){return a.Ma>>6&3};var xd=new Uint8Array(256),yd=[],zd=[],Ad=[],Bd=new Uint8Array(256),Cd=[];
function Dd(a,b){this.s=a;this.v=b;this.Ca=new Ab(64);this.fa=new Ab(64);this.i=this.o=this.lb=this.J=0;this.N=new Uint8Array(256);Ed(this);this.Fd=!1;this.ue=0;this.ob=this.nb=this.Uc=this.cc=!1;this.xb=[new Bb,new Bb];this.eb=a.u.eb;this.fb=this.bc=this.j=this.Ab=this.l=this.D=0;this.Bb=1;this.Tc=5;this.zb=!1;this.g=new ArrayBuffer(65536);this.Y=new Int8Array(this.g);this.C=new Uint8Array(this.g);this.X=new Int16Array(this.g);this.ba=new Uint16Array(this.g);this.Qa=new tb(this.g);this.Cb=this.B=
!1;this.Ya=22050;b.send("dac-tell-sampling-rate",this.Ya);this.h=1;this.O=170;this.L=0;this.Nc=new Uint8Array(256);this.F=new Ab(64);this.T=this.P=this.Sa=0;this.Jh=!1;this.ca=5;this.Yc=new Uint8Array(16);a.A.pd(544,this,this.wg,this.yg,this.li,this.ni);a.A.pd(904,this,this.wg,this.yg);a.A.pd(548,this,this.pi,this.si);K(a.A,550,this,this.ui);K(a.A,551,this,this.wi);K(a.A,552,this,this.yi);K(a.A,553,this,this.Ai);K(a.A,554,this,this.Ci);K(a.A,555,this,this.Ei);K(a.A,556,this,this.Gi);K(a.A,557,this,
this.Ii);a.A.pd(558,this,this.Ki,this.Mi);a.A.Lb(544,this,this.xg,this.zg,this.mi,this.oi);a.A.Lb(904,this,this.xg,this.zg);a.A.Lb(548,this,this.ri,this.ti);L(a.A,550,this,this.vi);L(a.A,551,this,this.xi);a.A.Lb(552,this,this.zi,this.Bi);L(a.A,554,this,this.Di);L(a.A,555,this,this.Fi);L(a.A,556,this,this.Hi);L(a.A,557,this,this.Ji);L(a.A,558,this,this.Li);L(a.A,559,this,this.Ni);a.A.pd(816,this,this.rj,this.tj);a.A.Lb(816,this,this.sj,this.uj);this.eb.cf.push({Je:this.pa,Gf:this});b.register("dac-request-data",
function(){!this.Ab||this.Cb?Fd(this):Gd(this)},this);b.register("speaker-has-initialized",function(){Ed(this)},this);b.send("speaker-confirm-initialized");Hd(this)}function Hd(a){a.Ca.clear();a.fa.clear();a.lb=0;a.o=0;a.Fd=!1;a.ue=0;a.cc=!1;a.Uc=!1;a.nb=!1;a.ob=!1;a.xb[0].clear();a.xb[1].clear();a.D=0;a.l=0;a.Ab=0;a.j=0;a.bc=0;a.fb=0;a.zb=!1;a.C.fill(0);a.B=!1;a.Cb=!1;a.O=170;a.L=0;a.Ya=22050;a.h=1;Id(a,1);a.Yc.fill(0);a.Nc.fill(0);a.Nc[5]=1;a.Nc[9]=248}p=Dd.prototype;
p.$=function(){var a=[];a[2]=this.J;a[3]=this.lb;a[4]=this.o;a[5]=this.i;a[6]=this.N;a[7]=this.Fd;a[8]=this.ue;a[9]=this.cc;a[10]=this.Uc;a[11]=this.nb;a[12]=this.ob;a[15]=this.D;a[16]=this.l;a[17]=this.Ab;a[18]=this.j;a[19]=this.bc;a[20]=this.fb;a[21]=this.Bb;a[22]=this.Tc;a[23]=this.zb;a[24]=this.C;a[25]=this.B;a[26]=this.Cb;a[27]=this.Ya;a[28]=this.h;a[29]=this.O;a[30]=this.L;a[31]=this.Nc;a[33]=this.cb;a[34]=this.ca;a[35]=this.Yc;return a};
p.H=function(a){this.J=a[2];this.lb=a[3];this.o=a[4];this.i=a[5];this.N=a[6];Jd(this);this.Fd=a[7];this.ue=a[8];this.cc=a[9];this.Uc=a[10];this.nb=a[11];this.ob=a[12];this.D=a[15];this.l=a[16];this.Ab=a[17];this.j=a[18];this.bc=a[19];this.fb=a[20];this.Bb=a[21];this.Tc=a[22];this.zb=a[23];this.C=a[24];this.B=a[25];this.Cb=a[26];this.Ya=a[27];this.h=a[28];this.O=a[29];this.L=a[30];this.Nc=a[31];this.cb=a[33];this.ca=a[34];this.Yc=a[35];this.g=this.C.buffer;this.Y=new Int8Array(this.g);this.X=new Int16Array(this.g);
this.ba=new Uint16Array(this.g);this.Qa=new tb(this.g);this.Cb?this.v.send("dac-disable"):this.v.send("dac-enable")};p.wg=function(){return 255};p.yg=function(){return 255};p.li=function(){return 255};p.ni=function(){return 255};p.pi=function(){return this.i};p.si=function(){var a=this.i,b=zd[a];return b?b.call(this):this.N[a]};p.ui=function(){return 255};p.wi=function(){return 255};p.yi=function(){return 255};p.Ai=function(){return 255};p.Ci=function(){this.fa.length&&(this.J=this.fa.shift());return this.J};
p.Ei=function(){return 255};p.Gi=function(){return 127};p.Ii=function(){return 255};p.Ki=function(){this.Yc[1]&&Id(this,1);return(this.fa.length&&!this.cc)<<7|127};p.Mi=function(){Id(this,2);return 0};p.xg=function(){this.P=0};p.zg=function(a){var b=Cd[this.P];b||(b=this.V);b.call(this,a,0,this.P)};p.mi=function(){this.T=0};p.oi=function(a){var b=Cd[this.T];b||(b=this.V);b.call(this,a,1,this.T)};p.ri=function(a){this.i=a};p.ti=function(a){Kd(this,this.i,a)};
p.vi=function(a){this.cc?this.cc=!1:a&&Hd(this);this.fa.clear();this.fa.push(170)};p.xi=function(){};p.zi=function(){};p.Bi=function(){};p.Di=function(){};p.Fi=function(){};p.Hi=function(a){0===this.lb?(this.lb=a,this.Ca.clear(),this.o=xd[a]):this.Ca.push(a);this.Ca.length>=this.o&&(a=yd[this.lb],a||(a=this.Yf),a.call(this),this.o=this.lb=0,this.Ca.clear())};p.Ji=function(){};p.Li=function(){};p.Ni=function(){};p.rj=function(){this.F.length&&(this.Sa=this.F.shift());return this.Sa};p.sj=function(){};
p.tj=function(){return 0|128*!this.F.length};p.uj=function(a){255==a&&(this.F.clear(),this.F.push(254))};p.Yf=function(){};function T(a,b,c){c||(c=Dd.prototype.Yf);for(var d=0;d<a.length;d++)xd[a[d]]=b,yd[a[d]]=c}function Ld(a){for(var b=[],c=0;16>c;c++)b.push(a+c);return b}T([14],2,function(){this.Nc[this.Ca.shift()]=this.Ca.shift()});T([15],1,function(){this.fa.clear();this.fa.push(this.Nc[this.Ca.shift()])});
T([16],1,function(){var a=this.Ca.shift();a=Md(a/127.5+-1);this.xb[0].push(a);this.xb[1].push(a);this.v.send("dac-enable")});T([20,21],2,function(){this.bc=1;this.fb=this.Bb;this.cc=this.nb=this.ob=this.zb=!1;Nd(this);Od(this)});T([22],2);T([23],2);T([28],0,function(){this.bc=1;this.fb=this.Bb;this.zb=!0;this.cc=this.nb=this.ob=!1;Od(this)});T([31],0);T([32],0,function(){this.fa.clear();this.fa.push(127)});T([36],2);T([44],0);T([48],0);T([49],0);T([52],0);T([53],0);T([54],0);T([55],0);T([56],0);
T([64],1,function(){Pd(this,1E6/(256-this.Ca.shift())/(this.Uc?2:1))});T([65,66],2,function(){Pd(this,this.Ca.shift()<<8|this.Ca.shift())});T([72],2,function(){Nd(this)});T([116],2);T([117],2);T([118],2);T([119],2);T([125],0);T([127],0);T([128],2);T([144],0,function(){this.bc=1;this.fb=this.Bb;this.zb=!0;this.ob=!1;this.cc=!0;this.nb=!1;Od(this)});T([145],0);T([152],0);T([153],0);T([160],0);T([168],0);
T(Ld(176),3,function(){if(!(this.lb&8)){var a=this.Ca.shift();this.bc=2;this.fb=this.Tc;this.zb=!!(this.lb&4);this.ob=!!(a&16);this.Uc=!!(a&32);this.nb=!0;Nd(this);Od(this)}});T(Ld(192),3,function(){if(!(this.lb&8)){var a=this.Ca.shift();this.bc=1;this.fb=this.Bb;this.zb=!!(this.lb&4);this.ob=!!(a&16);this.Uc=!!(a&32);this.nb=!1;Nd(this);Od(this)}});T([208],0,function(){this.Cb=!0;this.v.send("dac-disable")});T([209],0,function(){this.Fd=!0});T([211],0,function(){this.Fd=!1});
T([212],0,function(){this.Cb=!1;this.v.send("dac-enable")});T([213],0,function(){this.Cb=!0;this.v.send("dac-disable")});T([214],0,function(){this.Cb=!1;this.v.send("dac-enable")});T([216],0,function(){this.fa.clear();this.fa.push(255*this.Fd)});T([217,218],0,function(){this.zb=!1});T([224],1,function(){this.fa.clear();this.fa.push(~this.Ca.shift())});T([225],0,function(){this.fa.clear();this.fa.push(4);this.fa.push(5)});T([226],1);
T([227],0,function(){this.fa.clear();for(var a=0;44>a;a++)this.fa.push("COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.".charCodeAt(a));this.fa.push(0)});T([228],1,function(){this.ue=this.Ca.shift()});T([232],0,function(){this.fa.clear();this.fa.push(this.ue)});T([242,243],0,function(){this.Aa()});var Qd=new Uint8Array(256);Qd[14]=255;Qd[15]=7;Qd[55]=56;T([249],1,function(){var a=this.Ca.shift();this.fa.clear();this.fa.push(Qd[a])});function Kd(a,b,c){(b=Ad[b])&&b.call(a,c)}Dd.prototype.Ra=function(){return this.N[this.i]};
Dd.prototype.bb=function(a){this.N[this.i]=a};function Ed(a){a.N[4]=204;a.N[34]=204;a.N[38]=204;a.N[40]=0;a.N[46]=0;a.N[10]=0;a.N[48]=192;a.N[49]=192;a.N[50]=192;a.N[51]=192;a.N[52]=192;a.N[53]=192;a.N[54]=0;a.N[55]=0;a.N[56]=0;a.N[57]=0;a.N[59]=0;a.N[60]=31;a.N[61]=21;a.N[62]=11;a.N[63]=0;a.N[64]=0;a.N[65]=0;a.N[66]=0;a.N[67]=0;a.N[68]=128;a.N[69]=128;a.N[70]=128;a.N[71]=128;Jd(a)}function Jd(a){for(var b=1;b<a.N.length;b++)Bd[b]||Kd(a,b,a.N[b])}function Rd(a,b){b||(b=Dd.prototype.Ra);zd[a]=b}
function Sd(a,b){b||(b=Dd.prototype.bb);Ad[a]=b}function Td(a,b,c){Bd[a]=1;zd[a]=function(){return this.N[b]&240|this.N[c]>>>4};Ad[a]=function(d){this.N[a]=d;var e=d<<4&240|this.N[c]&15;Kd(this,b,d&240|this.N[b]&15);Kd(this,c,e)}}function Ud(a,b,c){zd[a]=Dd.prototype.Ra;Ad[a]=function(d){this.N[a]=d;this.v.send("mixer-volume",[b,c,(d>>>2)-62])}}Rd(0,function(){Ed(this);return 0});Sd(0);Td(4,50,51);Td(34,48,49);Td(38,52,53);Td(40,54,55);Td(46,56,57);Ud(48,0,0);Ud(49,0,1);Ud(50,2,0);Ud(51,2,1);Rd(59);
Sd(59,function(a){this.N[59]=a;this.v.send("mixer-volume",[1,2,6*(a>>>6)-18])});Rd(65);Sd(65,function(a){this.N[65]=a;this.v.send("mixer-gain-left",6*(a>>>6))});Rd(66);Sd(66,function(a){this.N[66]=a;this.v.send("mixer-gain-right",6*(a>>>6))});Rd(68);Sd(68,function(a){this.N[68]=a;a>>>=3;this.v.send("mixer-treble-left",a-(16>a?14:16))});Rd(69);Sd(69,function(a){this.N[69]=a;a>>>=3;this.v.send("mixer-treble-right",a-(16>a?14:16))});Rd(70);
Sd(70,function(a){this.N[70]=a;a>>>=3;this.v.send("mixer-bass-right",a-(16>a?14:16))});Rd(71);Sd(71,function(a){this.N[71]=a;a>>>=3;this.v.send("mixer-bass-right",a-(16>a?14:16))});Rd(128,function(){switch(this.ca){case 2:return 1;case 5:return 2;case 7:return 4;case 10:return 8;default:return 0}});Sd(128,function(a){a&1&&(this.ca=2);a&2&&(this.ca=5);a&4&&(this.ca=7);a&8&&(this.ca=10)});
Rd(129,function(){var a=0;switch(this.Bb){case 0:a|=1;break;case 1:a|=2;break;case 3:a|=8}switch(this.Tc){case 5:a|=32;break;case 6:a|=64;break;case 7:a|=128}return a});Sd(129,function(a){a&1&&(this.Bb=0);a&2&&(this.Bb=1);a&8&&(this.Bb=3);a&32&&(this.Tc=5);a&64&&(this.Tc=6);a&128&&(this.Tc=7)});Rd(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.Yc[b];return a});Dd.prototype.V=function(){};function Vd(a,b){b||(b=Dd.prototype.V);for(var c=0;c<a.length;c++)Cd[a[c]]=b}
function Wd(a,b){for(var c=[];a<=b;a++)c.push(a);return c}var U=new Uint8Array(32);U[0]=0;U[1]=1;U[2]=2;U[3]=3;U[4]=4;U[5]=5;U[8]=6;U[9]=7;U[10]=8;U[11]=9;U[12]=10;U[13]=11;U[16]=12;U[17]=13;U[18]=14;U[19]=15;U[20]=16;U[21]=17;Vd([1],function(a,b){this.Jh[b]=a&1});Vd([2]);Vd([3]);Vd([4],function(){});Vd([5],function(){});Vd([8],function(){});Vd(Wd(32,53),function(){});Vd(Wd(64,85),function(){});Vd(Wd(96,117),function(){});Vd(Wd(128,149),function(){});Vd(Wd(160,168),function(){});Vd(Wd(176,184),function(){});
Vd([189],function(){});Vd(Wd(192,200),function(){});Vd(Wd(224,245),function(){});function Pd(a,b){a.Ya=b;a.v.send("dac-tell-sampling-rate",b)}function Nd(a){a.D=1+(a.Ca.shift()<<0)+(a.Ca.shift()<<8)}function Od(a){a.h=1;a.nb&&(a.h*=2);a.l=a.D*a.h;a.j=1024*a.h;a.j=Math.min(Math.max(a.l>>2&-4,32),a.j);a.B=!0;a.eb.Yb[a.fb]||a.pa(a.fb)}Dd.prototype.pa=function(a){a===this.fb&&this.B&&(this.B=!1,this.Ab=this.l,this.Cb=!1,this.v.send("dac-enable"))};
function Gd(a){var b=Math.min(a.Ab,a.j),c=Math.floor(b/a.h);a.eb.be(a.Qa,0,b,a.fb,d=>{if(!d){d=a.nb?32767.5:127.5;var e=a.ob?0:-1,g=a.Uc?1:2,f;a.nb?f=a.ob?a.X:a.ba:f=a.ob?a.Y:a.C;for(var h=0,k=0;k<c;k++)for(var l=Md(f[k]/d+e),q=0;q<g;q++)a.xb[h].push(l),h^=1;Fd(a);a.Ab-=b;a.Ab||(a.Aa(a.bc),a.zb&&(a.Ab=a.l))}})}function Fd(a){if(a.xb[0].length){var b=Cb(a.xb[0],a.xb[0].length),c=Cb(a.xb[1],a.xb[1].length);a.v.send("dac-send-data",[b,c],[b.buffer,c.buffer])}}
Dd.prototype.Aa=function(a){this.Yc[a]=1;this.s.Ka(this.ca)};function Id(a,b){a.Yc[b]=0;Jb(a.s,a.ca)}function Md(a){return-1*(-1>a)+1*(1<a)+(-1<=a&&1>=a)*a};function ka(a,b){this.s=a;this.Ha=a.u.Ha;this.He=b.He;this.K=[244,26,b.He&255,b.He>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.Rg&255,b.Rg>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.K=this.K.concat(Array(256-this.K.length).fill(0));this.Ia=b.Ia;this.ib=[];this.name=b.name;this.i=this.B=0;this.l=new Uint32Array(4);this.h=new Uint32Array(4);for(var c of b.Fe.features)this.l[c>>>5]|=1<<(c&31),this.h[c>>>5]|=1<<(c&31);b.Fe.features.includes(32);this.C=
!0;this.j=0;this.F=!1;this.D=0;this.Xa=[];for(var d of b.Fe.Xa)this.Xa.push(new Xd(a,this,d));this.o=0;this.g=this.Xa[0];this.hc=0;c=[];c.push(Yd(this,b.Fe));c.push(Zd(b.notification));c.push($d(this,b.hc));b.Vf&&(d=c.push,b=b.Vf,b={type:4,Ad:3,port:b.Vc,ye:!1,offset:0,de:new Uint8Array(0),td:b.td},d.call(c,b));ae(this,c);Tb(a.u.Ha,this);this.reset()}
function Yd(a,b){return{type:1,Ad:0,port:b.Vc,ye:!1,offset:0,de:new Uint8Array(0),td:[{bytes:4,name:"device_feature_select",read:()=>a.B,write:c=>{a.B=c}},{bytes:4,name:"device_feature",read:()=>a.l[a.B]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>a.i,write:c=>{a.i=c}},{bytes:4,name:"driver_feature",read:()=>a.h[a.i]||0,write:c=>{const d=a.l[a.i];a.i<a.h.length&&(a.h[a.i]=c&d);a.C=a.C&&!(c&~d)}},{bytes:2,name:"msix_config",read:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",
read:()=>a.Xa.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>a.j,write:c=>{0===c&&a.reset();c&~a.j&4&&a.j&64&&(a.F=!0,a.j&4&&a.Aa(2));a.C||(c&=-9);a.j=c}},{bytes:1,name:"config_generation",read:()=>a.D,write:()=>{}},{bytes:2,name:"queue_select",read:()=>a.o,write:c=>{a.o=c;a.o<a.Xa.length||(a.g=null)}},{bytes:2,name:"queue_size",read:()=>a.g?a.g.size:0,write:c=>{if(a.g){c&c-1&&(c=1<<sb(c-1)+1);c>a.g.Kc&&(c=a.g.Kc);var d=a.g;d.size=c;d.o=c-1}}},{bytes:2,name:"queue_msix_vector",read:()=>
65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>a.g?a.g.enabled|0:0,write:c=>{a.g&&1===c&&(c=a.g,c.l&&c.h&&c.g&&(a.g.enabled=!0))}},{bytes:2,name:"queue_notify_off",read:()=>a.g?a.g.me:0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>a.g?a.g.l:0,write:c=>{a.g&&(a.g.l=c)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>a.g?a.g.h:0,write:c=>{a.g&&(a.g.h=c)}},{bytes:4,name:"queue_avail (high dword)",read:()=>
0,write:()=>{}},{bytes:4,name:"queue_used (low dword)",read:()=>a.g?a.g.g:0,write:c=>{a.g&&(a.g.g=c)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}}function Zd(a){const b=[];let c;c=a.Kj?0:2;for(const [d,e]of a.Oh.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,Ad:1,port:a.Vc,ye:!1,offset:0,de:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),td:b}}
function $d(a,b){return{type:3,Ad:2,port:b.Vc,ye:!1,offset:0,de:new Uint8Array(0),td:[{bytes:1,name:"isr_status",read:()=>{const c=a.hc;a.hc=0;mc(a.Ha,a.Ia);return c},write:()=>{}}]}}
function ae(a,b){let c=a.K[52]=64;var d=c;for(const g of b){b=16+g.de.length;d=c;c=d+b;var e=g.td.reduce((f,h)=>f+h.bytes,0);e+=g.offset;e=16>e?16:1<<sb(e-1)+1;a.ib[g.Ad]={size:e};a.K[d]=9;a.K[d+1]=c;a.K[d+2]=b;a.K[d+3]=g.type;a.K[d+4]=g.Ad;a.K[d+5]=0;a.K[d+6]=0;a.K[d+7]=0;a.K[d+8]=g.offset&255;a.K[d+9]=g.offset>>>8&255;a.K[d+10]=g.offset>>>16&255;a.K[d+11]=g.offset>>>24;a.K[d+12]=e&255;a.K[d+13]=e>>>8&255;a.K[d+14]=e>>>16&255;a.K[d+15]=e>>>24;for(const [f,h]of g.de.entries())a.K[d+16+f]=h;d=16+4*
g.Ad;a.K[d]=g.port&254|!g.ye;a.K[d+1]=g.port>>>8&255;a.K[d+2]=g.port>>>16&255;a.K[d+3]=g.port>>>24&255;d=g.port+g.offset;for(const f of g.td){let h=f.read;b=f.write;if(!g.ye){e=function(l){return h(l&-2)>>((l&1)<<3)&255};const k=function(l){return h(l&-4)>>((l&3)<<3)&255};switch(f.bytes){case 4:K(a.s.A,d,a,k,void 0,h);L(a.s.A,d,a,void 0,void 0,b);break;case 2:K(a.s.A,d,a,e,h);L(a.s.A,d,a,void 0,b);break;case 1:K(a.s.A,d,a,h),L(a.s.A,d,a,b)}}d+=f.bytes}}a.K[c]=9;a.K[c+1]=0;a.K[c+2]=20;a.K[c+3]=5;a.K[c+
4]=0;a.K[c+5]=0;a.K[c+6]=0;a.K[c+7]=0;a.K[c+8]=0;a.K[c+9]=0;a.K[c+10]=0;a.K[c+11]=0;a.K[c+12]=0;a.K[c+13]=0;a.K[c+14]=0;a.K[c+15]=0;a.K[c+16]=0;a.K[c+17]=0;a.K[c+18]=0;a.K[c+19]=0}ka.prototype.$=function(){let a=[];a[0]=this.B;a[1]=this.i;a[2]=this.l;a[3]=this.h;a[4]=this.C;a[5]=this.j;a[6]=this.F;a[7]=this.D;a[8]=this.hc;a[9]=this.o;return a=a.concat(this.Xa)};
ka.prototype.H=function(a){this.B=a[0];this.i=a[1];this.l=a[2];this.h=a[3];this.C=a[4];this.j=a[5];this.F=a[6];this.D=a[7];this.hc=a[8];this.o=a[9];let b=0;for(let c of a.slice(10))this.Xa[b].H(c),b++;this.g=this.Xa[this.o]||null};ka.prototype.reset=function(){this.i=this.B=0;this.h.set(this.l);this.C=!0;this.o=this.j=0;this.g=this.Xa[0];for(const a of this.Xa)a.reset();this.F=!1;this.hc=this.D=0;mc(this.Ha,this.Ia)};ka.prototype.Aa=function(a){this.hc|=a;this.Ha.Aa(this.Ia)};
function Xd(a,b,c){this.s=a;this.ab=b;this.Kc=this.size=c.Kc;this.o=this.size-1;this.enabled=!1;this.me=c.me;this.i=this.g=this.j=this.h=this.l=0;this.reset()}Xd.prototype.$=function(){const a=[];a[0]=this.size;a[1]=this.Kc;a[2]=this.enabled;a[3]=this.me;a[4]=this.l;a[5]=this.h;a[6]=this.j;a[7]=this.g;a[8]=this.i;return a};Xd.prototype.H=function(a){this.size=a[0];this.Kc=a[1];this.enabled=a[2];this.me=a[3];this.l=a[4];this.h=a[5];this.j=a[6];this.g=a[7];this.i=a[8];this.o=this.size-1};
Xd.prototype.reset=function(){this.enabled=!1;this.i=this.g=this.j=this.h=this.l=0;var a=this.Kc;this.size=a;this.o=a-1};function la(a){return(a.s.Oa(a.h+2)&a.o)!==a.j}
function ma(a,b){this.s=a.s;this.ab=a.ab;this.Ph=b;this.i=[];this.pf=this.g=this.h=0;this.Of=[];this.qf=this.Be=this.Nf=0;let c=a.l;var d=b;b=0;let e=a.size,g=!1;const f=0<(this.ab.h[0]&268435456);do{var h=a,k=c;h={ef:h.s.g(k+16*d),bk:h.s.g(k+16*d+4),Ne:h.s.g(k+16*d+8),flags:h.s.Oa(k+16*d+12),next:h.s.Oa(k+16*d+14)};if(f&&h.flags&4)c=h.ef,b=d=0,e=h.Ne/16;else{if(h.flags&2)g=!0,this.Of.push(h);else{if(g)break;this.i.push(h);this.pf+=h.Ne}b++;if(b>e)break;if(h.flags&1)d=h.next;else break}}while(1)}
function ua(a,b){let c=0,d=b.length;for(;d&&a.h!==a.i.length;){var e=a.i[a.h],g=e.ef+a.g;let l=e.Ne-a.g;l>d?(l=d,a.g+=d):(a.h++,a.g=0);e=b;var f=e.set,h=a.s,k=l;k&&(h.Me(g),h.Me(g+k-1));f.call(e,h.Na.subarray(g,g+k),c);c+=l;d-=l}};function be(){this.je={};this.g=void 0}be.prototype.register=function(a,b,c){var d=this.je[a];void 0===d&&(d=this.je[a]=[]);d.push({Je:b,Gf:c})};be.prototype.unregister=function(a,b){var c=this.je[a];void 0!==c&&(this.je[a]=c.filter(function(d){return d.Je!==b}))};be.prototype.send=function(a,b){if(this.g&&(a=this.g.je[a],void 0!==a))for(var c=0;c<a.length;c++){var d=a[c];d.Je.call(d.Gf,b)}};function ce(){var a=new be,b=new be;a.g=b;b.g=a;return[a,b]};function de(){};function jb(a,b,c){this.Xg=c;this.xa=b;ee(this);b=Object.create(null);b.m=this.xa.exports.memory;for(var d of Object.keys(this.xa.exports))d.startsWith("_")||d.startsWith("zstd")||d.endsWith("_js")||(b[d]=this.xa.exports[d]);this.Wg=b;this.Ja=d=this.xa.exports.memory;this.G=Q(Uint32Array,d,812,1);this.Na=new Uint8Array(0);this.vc=new Int32Array(this.Na.buffer);this.Sa=Q(Uint8Array,d,724,8);this.cb=Q(Int32Array,d,736,8);this.bb=Q(Uint32Array,d,768,8);this.Qa=Q(Int32Array,d,800,1);this.Xb=Q(Int32Array,
d,564,1);this.Wb=Q(Int32Array,d,568,1);this.Ob=Q(Int32Array,d,572,1);this.Ub=Q(Int32Array,d,576,1);this.Kg=Q(Int32Array,d,1128,1);this.wc=Q(Uint32Array,d,540,8);this.Ma=Q(Int32Array,d,580,8);this.Pb=Q(Uint8Array,d,612,1);this.ba=Q(Int32Array,d,804,1);this.ub=Q(Int32Array,d,808,1);this.h=Q(Uint8Array,d,616,1);this.uc=Q(Int32Array,d,620,1);this.Rb=Q(Int32Array,d,624,1);this.ng=Q(Int32Array,d,636,1);this.Jg=Q(Int32Array,d,640,1);this.pg=Q(Int32Array,d,644,1);this.xc=Q(Int32Array,d,648,1);this.flags=
Q(Int32Array,d,120,1);this.Sb=Q(Int32Array,d,100,1);this.sc=Q(Int32Array,d,96,1);this.qc=Q(Int32Array,d,104,1);Q(Int32Array,d,112,1);this.Pj=Q(Uint32Array,d,960,2);this.u={};this.B=Q(Int32Array,d,556,1);this.zc=Q(Int32Array,d,560,1);Q(Uint8Array,d,548,1);this.F=Q(Uint8Array,d,552,1);this.i=[];this.l=[];this.pa=[];this.j=[];this.Bd={kg:null,Sd:null};this.Th=Q(Uint32Array,d,664,1);this.D=Q(Int32Array,d,64,8);this.Tb=Q(Int32Array,d,1152,32);this.X=Q(Uint8Array,d,816,1);this.X[0]=255;this.Y=Q(Uint8Array,
d,1032,1);this.Y[0]=0;this.J=Q(Uint16Array,d,1036,1);this.J[0]=895;this.Vj=Q(Uint16Array,d,1040,1);this.Vj[0]=0;this.P=Q(Int32Array,d,1048,1);this.P[0]=0;this.T=Q(Int32Array,d,1052,1);this.T[0]=0;this.V=Q(Int32Array,d,1044,1);this.V[0]=0;this.L=Q(Int32Array,d,1056,1);this.L[0]=0;this.O=Q(Int32Array,d,1060,1);this.O[0]=0;this.$c=Q(Int32Array,d,832,32);Q(Int32Array,d,824,1);this.tb=Q(Uint16Array,d,668,8);this.Qb=Q(Int32Array,d,684,8);this.Ac=Q(Int32Array,d,968,8);this.dh=Q(Uint32Array,d,716,1);this.bh=
Q(Uint32Array,d,720,1);this.Wa=[];this.mf=0;this.fd=[];this.A=void 0;this.v=a;this.ke(0,0);fe(this)}
function ee(a){const b=c=>{const d=a.xa.exports[c];console.assert(d,"Missing import: "+c);return d};a.Ra=b("reset_cpu");b("getiopl");b("get_eflags");a.o=b("get_eflags_no_arith");a.C=b("pic_call_irq");a.Tj=b("do_many_cycles_native");b("cycle_internal");a.od=b("read8");a.Oa=b("read16");a.g=b("read32s");a.df=b("write8");a.Ae=b("write16");a.Lc=b("write32");a.Me=b("in_mapped_range");b("fpu_load_tag_word");b("fpu_load_status_word");b("fpu_get_sti_f64");b("translate_address_system_read_js");a.Vb=b("get_seg_cs");
b("get_real_eip");b("clear_tlb");a.Wj=b("full_clear_tlb");a.Mg=b("update_state_flags");a.ke=b("set_tsc");a.Zg=b("store_current_tsc");a.Yg=b("set_cpuid_level");a.Xj=b("jit_clear_cache_js");a.Uh=b("jit_dirty_cache");a.Nj=b("codegen_finalize_finished");a.Mj=b("allocate_memory");a.hh=b("zero_memory");a.ah=b("svga_allocate_memory");a.$g=b("svga_allocate_dest_buffer");a.eh=b("svga_fill_pixel_buffer");a.lg=b("svga_mark_dirty");a.Tg=b("zstd_create_ctx");a.Vg=b("zstd_get_src_ptr");a.Ug=b("zstd_free_ctx");
a.Td=b("zstd_read");a.Ud=b("zstd_read_free")}
jb.prototype.$=function(){var a=[];a[0]=this.G[0];a[1]=this.Sa;a[2]=this.cb;a[3]=this.bb;a[4]=this.Qa[0];a[5]=this.Wb[0];a[6]=this.Xb[0];a[7]=this.Ub[0];a[8]=this.Ob[0];a[9]=this.wc[0];a[10]=this.Ma;a[11]=this.Pb[0];a[13]=this.ba[0];a[16]=this.ub[0];a[17]=this.h[0];a[18]=this.uc[0];a[19]=this.Rb[0];a[22]=this.ng[0];a[23]=this.pg[0];a[24]=this.Jg[0];a[25]=this.xc[0];a[26]=this.flags[0];a[27]=this.Sb[0];a[28]=this.qc[0];a[30]=this.sc[0];a[37]=this.B[0];a[38]=this.zc[0];a[39]=this.D;a[40]=this.tb;a[41]=
this.Qb;a[42]=this.Ac;this.Zg();a[43]=this.Pj;a[45]=this.u.Lf;a[46]=this.u.Mc;a[47]=this.u.Ic;a[48]=this.u.Ha;a[49]=this.u.eb;a[50]=this.u.ya;a[51]=this.u.gg;a[52]=this.u.Sd;a[53]=this.u.wf;a[54]=this.u.Jf;a[55]=this.u.lf;a[56]=this.u.ga;a[57]=this.u.M;a[58]=this.u.Ue;a[59]=this.u.sf;a[60]=this.u.jc;a[61]=this.u.Af;a[62]=this.Wa;a[63]=this.u.yc;a[64]=this.Kg[0];a[66]=this.$c;a[67]=this.Tb;a[68]=this.X[0];a[69]=this.Y[0];a[70]=this.J[0];a[71]=this.P[0];a[72]=this.T[0];a[73]=this.L[0];a[74]=this.O[0];
a[75]=this.V[0];var b=this.Na.length>>12,c=[];for(var d=0;d<b;d++){var e=d<<12;e=this.vc.subarray(e>>2,e+4096>>2);let h=!0;for(let k=0;k<e.length;k++)if(0!==e[k]){h=!1;break}h||c.push(d)}b=new Db(b);d=new Uint8Array(c.length<<12);for(let [h,k]of c.entries())b.set(k,1),c=k<<12,d.set(this.Na.subarray(c,c+4096),h<<12);const {bi:g,jh:f}={jh:b,bi:d};a[77]=g;a[78]=new Uint8Array(f.pb());a[79]=this.u.ve;a[80]=this.u.we;a[81]=this.u.xe;return a};
jb.prototype.H=function(a){this.G[0]=a[0];this.Na.length!==this.G[0]&&console.warn("Note: Memory size mismatch. we="+this.Na.length+" state="+this.G[0]);this.Sa.set(a[1]);this.cb.set(a[2]);this.bb.set(a[3]);this.Qa[0]=a[4];this.Wb[0]=a[5];this.Xb[0]=a[6];this.Ub[0]=a[7];this.Ob[0]=a[8];this.wc[0]=a[9];this.Ma.set(a[10]);this.Pb[0]=a[11];this.ba[0]=a[13];this.ub[0]=a[16];this.h[0]=a[17];this.uc[0]=a[18];this.Rb[0]=a[19];this.ng[0]=a[22];this.pg[0]=a[23];this.Jg[0]=a[24];this.xc[0]=a[25];this.flags[0]=
a[26];this.Sb[0]=a[27];this.qc[0]=a[28];this.sc[0]=a[30];this.B[0]=a[37];this.zc[0]=a[38];this.D.set(a[39]);this.tb.set(a[40]);this.Qb.set(a[41]);a[42]&&this.Ac.set(a[42]);this.ke(a[43][0],a[43][1]);this.u.Lf&&this.u.Lf.H(a[45]);this.u.Mc&&this.u.Mc.H(a[46]);this.u.Ic&&this.u.Ic.H(a[47]);this.u.Ha&&this.u.Ha.H(a[48]);this.u.eb&&this.u.eb.H(a[49]);this.u.ya&&this.u.ya.H(a[50]);this.u.gg&&this.u.gg.H(a[51]);this.u.Sd&&this.u.Sd.H(a[52]);this.u.wf&&this.u.wf.H(a[53]);this.u.Jf&&this.u.Jf.H(a[54]);this.u.lf&&
this.u.lf.H(a[55]);this.u.ga&&this.u.ga.H(a[56]);this.u.M&&this.u.M.H(a[57]);this.u.Ue&&this.u.Ue.H(a[58]);this.u.sf&&this.u.sf.H(a[59]);this.u.jc&&this.u.jc.H(a[60]);this.u.Af&&this.u.Af.H(a[61]);this.u.ve&&this.u.ve.H(a[79]);this.u.we&&this.u.we.H(a[80]);this.u.xe&&this.u.xe.H(a[81]);this.Wa=a[62];this.u.yc&&this.u.yc.H(a[63]);this.Kg[0]=a[64];this.$c.set(a[66]);this.Tb.set(a[67]);this.X[0]=a[68];this.Y[0]=a[69];this.J[0]=a[70];this.P[0]=a[71];this.T[0]=a[72];this.L[0]=a[73];this.O[0]=a[74];this.V[0]=
a[75];var b=new Db(a[78].buffer);a=a[77];this.hh(this.G[0]);const c=this.G[0]>>12;let d=0;for(let e=0;e<c;e++)if(b.get(e)){let g=d<<12;this.Na.set(a.subarray(g,g+4096),e<<12);d++}this.Mg();this.Wj();this.Xj()};function lc(a){a.Ra();a.Wa=[];a.u.ab&&a.u.ab.reset();qb(a)}
function ge(a,b){1048576>b?b=1048576:0>(b|0)&&(b=Math.pow(2,31)-131072);b=(b-1|131071)+1|0;console.assert(0===a.G[0],"Expected uninitialised memory");a.G[0]=b;const c=a.Mj(b);a.Na=Q(Uint8Array,a.Ja,c,b);a.vc=Q(Uint32Array,a.Ja,c,b>>2)}
jb.prototype.hb=function(a,b){ge(this,"number"===typeof a.G?a.G:67108864);a.Dd&&this.Yg(a.Dd);this.F[0]=+a.ya;this.Ra();var c=new eb(this);this.A=c;this.Bd.kg=a.Bd;this.Bd.Sd=a.Sj;qb(this);if(a.vb){const {ai:e}=he(this.Na,a.vb,a.Xc,a.Pc||"");e&&this.fd.push(e)}K(c,179,this,function(){return 0});var d=0;K(c,146,this,function(){return d});L(c,146,this,function(e){d=e});K(c,1297,this,function(){return this.mf<this.Wa.length?this.Wa[this.mf++]:0});L(c,1296,this,void 0,function(e){function g(k){return new Uint8Array((new Int32Array([k])).buffer)}
function f(k){return k>>8|k<<8&65280}function h(k){return k<<24|k<<8&16711680|k>>8&65280|k>>>24}this.mf=0;if(0===e)this.Wa=g(1431127377);else if(1===e)this.Wa=g(0);else if(3===e)this.Wa=g(this.G[0]);else if(5===e)this.Wa=g(1);else if(15===e)this.Wa=g(1);else if(13===e)this.Wa=new Uint8Array(16);else if(25===e){e=new Int32Array(4+64*this.fd.length);const k=new Uint8Array(e.buffer);e[0]=h(this.fd.length);for(let l=0;l<this.fd.length;l++){const {name:q,data:n}=this.fd[l],t=4+64*l;e[t>>2]=h(n.length);
e[t+4>>2]=f(49152+l);for(let m=0;m<q.length;m++)k[t+8+m]=q.charCodeAt(m)}this.Wa=k}else this.Wa=32768<=e&&49152>e?g(0):49152<=e&&e-49152<this.fd.length?this.fd[e-49152].data:g(0)});this.u={};a.Vh&&(this.u.jc=new Vc(this),this.u.Ha=new hc(this),this.F[0]&&(this.u.yc=new md(this),this.u.Mc=new fd(this),this.u.ya=new dd(this)),this.u.Ic=new Wc(this),ie(this,this.u.Ic,a),this.u.eb=new qc(this),this.u.Sd=new Cc(this,b,a.ha||8388608),this.u.wf=new Rc(this,b),this.u.Jf=new Zc(this,1016,b),a.ve&&(this.u.ve=
new Zc(this,760,b)),a.we&&(this.u.we=new Zc(this,1E3,b)),a.xe&&(this.u.xe=new Zc(this,744,b)),this.u.lf=new nc(this,a.ma),c=0,a.M&&(this.u.M=new Hb(this,a.M,a.Ke,!1,c++,b)),a.ga&&(this.u.ga=new Hb(this,a.ga,void 0,!0,c++,b)),this.u.Ue=new vc(this,b),a.Fh&&(this.u.sf=new sd(this,b,a.vf,a.Gb)),a.Db&&(this.u.Lf=new fa(a.Db,this,b)),this.u.Af=new Dd(this,b));a.ed&&je(this,a.ed)};
function je(a,b){if(8192>b.byteLength){var c=new Int32Array(2048);(new Uint8Array(c.buffer)).set(new Uint8Array(b))}else c=new Int32Array(b,0,2048);for(var d=0;8192>d;d+=4)if(464367618===c[d>>2]){var e=c[d+4>>2];if(!(464367618+e+c[d+8>>2]|0)){a.D[0]=732803074;a.D[3]=31744;a.Lc(31744,0);a.Ma[0]=1;a.Qa[0]=1;a.flags[0]=2;a.ba[0]=1;a.ub[0]=1;for(var g=0;6>g;g++)a.Sa[g]=0,a.cb[g]=0,a.bb[g]=4294967295,a.tb[g]=45058;if(e&65536){var f=c[d+16>>2];g=c[d+20>>2];e=c[d+28>>2];b=new Uint8Array(b,d-(c[d+12>>2]-
f),0===g?void 0:g-f);ra(a,b,f);a.B[0]=a.Vb()+e|0}else if(1179403647===c[0]){c=ke(b);a.B[0]=a.Vb()+c.Qh.Gh|0;for(f of c.Dj)0!==f.type&&1===f.type&&f.qg+f.Yh<a.G[0]&&f.$f&&(c=new Uint8Array(b,f.offset,f.$f),ra(a,c,f.qg))}a.A.Lb(244,a,function(h){console.log("Test exited with code "+yb(h,2));throw"HALT";},function(){},function(){},function(){});for(let h=0;15>=h;h++){function k(l){l?this.Ka(h):Jb(this,h)}L(a.A,8192+h,a,k,k,k)}a.Mg();break}}}
function ie(a,b,c){var d=c.oc||531;b.W[56]=1|d>>4&240;b.W[61]=d&255;b.W[21]=128;b.W[22]=2;d=0;1048576<=a.G[0]&&(d=a.G[0]-1048576>>10,d=Math.min(d,65535));b.W[23]=d&255;b.W[24]=d>>8&255;b.W[48]=d&255;b.W[49]=d>>8&255;d=0;16777216<=a.G[0]&&(d=a.G[0]-16777216>>16,d=Math.min(d,65535));b.W[52]=d&255;b.W[53]=d>>8&255;b.W[91]=0;b.W[92]=0;b.W[93]=0;b.W[20]=47;b.W[95]=0;c.Hh&&(b.W[63]=1)}
function qb(a){var b=a.Bd.kg,c=a.Bd.Sd;if(b){var d=new Uint8Array(b);ra(a,d,1048576-b.byteLength);if(c){var e=new Uint8Array(c);ra(a,e,786432);hb(a.A,4272947200,1048576,function(g){g=g-4272947200|0;return g<e.length?e[g]:0},function(){})}hb(a.A,4293918720,1048576,function(g){return this.Na[g&1048575]}.bind(a),function(g,f){this.Na[g&1048575]=f}.bind(a))}}
function le(a,b,c,d,e,g){const f=new Uint8Array(a.Ja.buffer,e>>>0,g>>>0);WebAssembly.instantiate(f,{e:a.Wg}).then(h=>{a.xa.Mf.set(b+1024,h.instance.exports.f);a.Nj(b,c,d);a.gh&&a.gh(f)})}function mb(a){if(a.o()&512){const b=ob(a,nb());pb(a);return b}return 100}function ob(a,b){var c=a.u.Ue.sb(b,!1);var d=a.u.Ic.sb(b,!1);let e=100,g=100;a.F[0]&&(e=a.u.ya.sb(b),g=a.u.Mc.sb(b));return Math.min(c,d,100,e,g)}function pb(a){a.o()&512&&(me(a),a.Xg())}
function me(a){a.o();a.u.jc&&a.u.jc.Vd();a.u.Mc&&a.u.Mc.Vd()}jb.prototype.Ka=function(a){this.u.jc&&this.u.jc.Rd(a);this.u.yc&&this.u.yc.Rd(a)};function Jb(a,b){a.u.jc&&a.u.jc.Wd(b);a.u.yc&&a.u.yc.Wd(b)}"undefined"!==typeof window?window.CPU=jb:"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.CPU=jb:"function"===typeof importScripts&&(self.CPU=jb);function fe(a){var b={};a.debug=b;b.hb=function(){};b.tk=function(){};b.lk=function(){};b.$=function(){};b.nk=function(){};b.mk=function(){};b.kk=function(){if(a.Ma[4]&32)for(var g=0;4>g;g++)a.g(a.Ma[3]+8*g)};b.ik=function(){};b.jk=function(){};b.sk=function(){};b.yk=function(){};b.Gk=function(){};b.ek=function(){};let c,d;b.hk=function(g,f,h){if(!d){if(void 0===c&&(c="function"===typeof require?require("./capstone-x86.min.js"):window.cs,void 0===c))return;d=[new c.Capstone(c.ARCH_X86,c.MODE_16),
new c.Capstone(c.ARCH_X86,c.MODE_32)]}try{d[g].disasm(f,h).forEach(function(k){de(yb(k.dk>>>0)+": "+xb(k.bytes.map(l=>yb(l,2).slice(-2)).join(" "),20)+" "+k.mnemonic+" "+k.op_str)})}catch(k){de("Could not disassemble: "+Array.from(f).map(l=>yb(l,2)).join(" "))}};let e;b.pk=function(g){if(void 0===e&&(e="function"===typeof require?require("./libwabt.js"):new window.WabtModule,void 0===e))return;g=g.slice();try{var f=e.readWasm(g,{Dk:!1});f.generateNames();f.applyNames();f.toText({rk:!0,vk:!0})}catch(l){var h=
new Blob([g]),k=document.createElement("a");k.download="failed.wasm";k.href=window.URL.createObjectURL(h);k.dataset.downloadurl=["application/octet-stream",k.download,k.href].join(":");k.click();window.URL.revokeObjectURL(k.src);console.log(l.toString())}finally{f&&f.va()}}};let ne=DataView.prototype,oe={size:1,get:ne.getUint8,set:ne.setUint8},pe={size:2,get:ne.getUint16,set:ne.setUint16},W={size:4,get:ne.getUint32,set:ne.setUint32},re=qe([{Wh:W},{nh:oe},{data:oe},{Qj:oe},{Ak:oe},{$j:oe},{Bk:function(a){return{size:a,get:()=>-1}}(7)},{type:pe},{xk:pe},{Rj:W},{Gh:W},{di:W},{Hj:W},{flags:W},{Bh:pe},{ug:pe},{vg:pe},{Pg:pe},{Qg:pe},{Fk:pe}]);console.assert(52===re.reduce((a,b)=>a+b.size,0));let se=qe([{type:W},{offset:W},{Hk:W},{qg:W},{$f:W},{Yh:W},{flags:W},{align:W}]);
console.assert(32===se.reduce((a,b)=>a+b.size,0));let te=qe([{name:W},{type:W},{flags:W},{ak:W},{offset:W},{size:W},{link:W},{info:W},{ck:W},{qk:W}]);console.assert(40===te.reduce((a,b)=>a+b.size,0));function qe(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 ke(a){var b=new DataView(a);let [c,d]=ue(b,re);console.assert(52===d);console.assert(1179403647===c.Wh,"Bad magic");console.assert(1===c.nh,"Unimplemented: 64 bit elf");console.assert(1===c.data,"Unimplemented: big endian");console.assert(1===c.Qj,"Bad version0");console.assert(2===c.type,"Unimplemented type");console.assert(1===c.Rj,"Bad version1");console.assert(52===c.Bh,"Bad header size");console.assert(32===c.ug,"Bad program header size");console.assert(40===c.Pg,"Bad section header size");
[a]=ve(new DataView(b.buffer,b.byteOffset+c.di,c.ug*c.vg),se,c.vg);[b]=ve(new DataView(b.buffer,b.byteOffset+c.Hj,c.Pg*c.Qg),te,c.Qg);return{Qh:c,Dj:a,Ek:b}}function ue(a,b){let c={},d=0;for(let 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 ve(a,b,c){let d=[],e=0;for(var g=0;g<c;g++){let [f,h]=ue(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(f);e+=h}return[d,e]};function he(a,b,c,d){var e=new Uint8Array(b);const g=new Uint16Array(b);var f=new Uint32Array(b),h=e[497]||4;if(43605===g[255]&&1400005704===(g[257]|g[258]<<16)){var k=e[529];e[528]=255;e[529]=k&-97|128;g[274]=56832;g[253]=65535;d+="\x00";f[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);h=512*(h+1);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));f[134]=h;f[135]=e;a.set(d,524288);a.set(b,1048576);a=new Uint8Array(256);(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;f=a[c]=0;for(b=0;b<a.length;b++)f+=a[b];a[c]=-f;return{ai:{name:"genroms/kernel.bin",data:a}}}};var Ga=16384,La=4;function we(a){this.g=[];this.C=[];this.j=a;this.B={nf:0};this.h={};this.l=274877906944;this.o=0;this.i=[];Fa(this,"",-1)}we.prototype.$=function(){let a=[];a[0]=this.g;a[1]=this.B.nf;a[2]=[];for(const [b,c]of Object.entries(this.h))0===(this.g[b].mode&Ga)&&a[2].push([b,c]);a[3]=this.l;a[4]=this.o;return a=a.concat(this.i)};
we.prototype.H=function(a){this.g=a[0].map(b=>{const c=new xe(0);c.H(b);return c});this.B.nf=a[1];this.h={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.h[b]=c;this.l=a[3];this.o=a[4];this.i=a.slice(5)};function Ba(a,b,c){var d=a.g[b];0==d.status||2==d.status?c():5===d.status?Ba(Z(a,d),d.g,c):a.C.push({id:b,Zj:c})}
function ye(a,b,c){var d=ze(a);const e=b[0];d.size=b[1];d.ic=b[2];d.Ed=d.ic;d.Oc=d.ic;d.mode=b[3];d.uid=b[4];d.Ga=b[5];var g=d.mode&61440;if(g===Ga)for(Ae(a,d,c,e),c=a.g.length-1,b=b[6],d=0;d<b.length;d++)ye(a,b[d],c);else 32768===g?(d.status=2,d.sd=b[6],Ae(a,d,c,e)):40960===g&&(d.te=b[6],Ae(a,d,c,e))}function Be(a,b,c,d){const e=a.g[c],g=a.g[b];Ce(a,b);g.ia.has(d);g.ia.set(d,c);e.Ua++;Ce(a,c)&&(e.ia.has(".."),e.ia.has(".")||e.Ua++,e.ia.set(".",c),e.ia.set("..",b),g.Ua++)}
function De(a,b,c){const d=Sa(a,b,c),e=a.g[d],g=a.g[b];Ce(a,b);g.ia.delete(c)&&(e.Ua--,Ce(a,d)&&(e.ia.get(".."),e.ia.delete(".."),g.Ua--))}function Ae(a,b,c,d){-1!=c?(a.g.push(b),b.dc=a.g.length-1,Be(a,c,b.dc,d)):0==a.g.length&&(a.g.push(b),b.ia.set(".",0),b.ia.set("..",0),b.Ua=2)}
function xe(a){this.ia=new Map;this.Pe=this.Oe=this.ic=this.Oc=this.Ed=this.dc=this.Ga=this.uid=this.size=this.status=0;this.te="";this.mode=493;this.za={type:0,version:0,path:a};this.Ua=0;this.sd="";this.h=[];this.g=this.i=-1}
xe.prototype.$=function(){const a=[];a[0]=this.mode;a[1]=(this.mode&61440)===Ga?[...this.ia]:32768===(this.mode&61440)?this.sd:40960===(this.mode&61440)?this.te:49152===(this.mode&61440)?[this.Pe,this.Oe]:null;a[2]=this.h;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.Ga;a[7]=this.dc;a[8]=this.Ed;a[9]=this.Oc;a[10]=this.ic;a[11]=this.za.version;a[12]=this.za.path;a[13]=this.Ua;return a};
xe.prototype.H=function(a){this.mode=a[0];if((this.mode&61440)===Ga){this.ia=new Map;for(const [b,c]of a[1])this.ia.set(b,c)}else 32768===(this.mode&61440)?this.sd=a[1]:40960===(this.mode&61440)?this.te=a[1]:49152===(this.mode&61440)&&([this.Pe,this.Oe]=a[1]);this.h=[];for(const b of a[2]){const c=new Ee;c.H(b);this.h.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.Ga=a[6];this.dc=a[7];this.Ed=a[8];this.Oc=a[9];this.ic=a[10];this.za.type=(this.mode&61440)>>8;this.za.version=a[11];this.za.path=
a[12];this.Ua=a[13]};function Fe(a,b){Object.assign(b,a,{dc:b.dc,ia:b.ia,Ua:b.Ua})}function ze(a){const b=Math.round(Date.now()/1E3);a=new xe(++a.B.nf);a.Oc=a.Ed=a.ic=b;return a}function Fa(a,b,c){var d=a.g[c];if(0<=c&&5===d.status)return c=d.g,b=Fa(Z(a,d),b,c),Ge(a,d.i,b);d=ze(a);d.mode=511|Ga;0<=c&&(d.uid=a.g[c].uid,d.Ga=a.g[c].Ga,d.mode=a.g[c].mode&511|Ga);d.za.type=Ga>>8;Ae(a,d,c,b);return a.g.length-1}
function Ha(a,b,c){var d=a.g[c];if(5===d.status)return c=d.g,b=Ha(Z(a,d),b,c),Ge(a,d.i,b);d=ze(a);d.uid=a.g[c].uid;d.Ga=a.g[c].Ga;d.za.type=128;d.mode=a.g[c].mode&438|32768;Ae(a,d,c,b);return a.g.length-1}function Ea(a,b,c,d,e){var g=a.g[c];if(5===g.status)return c=g.g,b=Ea(Z(a,g),b,c,d,e),Ge(a,g.i,b);g=ze(a);g.Oe=d;g.Pe=e;g.uid=a.g[c].uid;g.Ga=a.g[c].Ga;g.za.type=192;g.mode=a.g[c].mode&438;Ae(a,g,c,b);return a.g.length-1}
function Da(a,b,c,d){var e=a.g[c];if(5===e.status)return c=e.g,b=Da(Z(a,e),b,c,d),Ge(a,e.i,b);e=ze(a);e.uid=a.g[c].uid;e.Ga=a.g[c].Ga;e.za.type=160;e.te=d;e.mode=40960;Ae(a,e,c,b);return a.g.length-1}async function He(a,b,c,d){var e=a.g[c];if(5===e.status)return c=e.g,d=await He(Z(a,e),b,c,d),Ge(a,e.i,d);e=Ha(a,b,c);b=a.g[e];c=new Uint8Array(d.length);c.set(d);await Ie(a,e,c);b.size=d.length;return e}
function Aa(a,b,c){var d=a.g[b];if(5===d.status)return Aa(Z(a,d),d.g,c);(d.mode&61440)==Ga&&Je(a,b);return!0}async function Ua(a,b){var c=a.g[b];if(5===c.status)return await Ua(Z(a,c),c.g);2===c.status&&a.j.g(c.sd);c.status==La&&(c.status=-1,await Ke(a,b))}
async function Ra(a,b,c,d,e){if(b==d&&c==e)return 0;var g=Sa(a,b,c);if(-1===g)return-2;var f=b;Ce(a,f);for(var h="";0!=f;)h="/"+Me(a,f)+h,f=Ne(a,f);if(-1!=Sa(a,d,e)&&(f=Ta(a,d,e),0>f))return f;h=a.g[g];var k=a.g[b];f=a.g[d];if(5===k.status||5===f.status)if(5===k.status&&k.i===f.i){if(a=await Ra(Z(a,k),k.g,c,f.g,e),0>a)return a}else{if(0===H(a,g).dc||!Ce(a,g)&&1<H(a,g).Ua)return-1;k=Sa(a,b,c);var l=a.g[k],q=new xe(-1);Ce(a,k);Object.assign(q,l);const n=a.g.length;a.g.push(q);q.dc=n;5===l.status&&a.i[l.i].g.set(l.g,
n);if(5!==l.status||0===l.g)De(a,b,c),Be(a,b,n,c);if(Ce(a,k)&&5!==l.status)for(const [t,m]of q.ia)"."!==t&&".."!==t&&Ce(a,m)&&a.g[m].ia.set("..",n);a.h[n]=a.h[k];delete a.h[k];l.ia=new Map;l.Ua=0;k=n;l=H(a,g);q=await Oa(a,k,0,l.size);5===f.status?(d=Z(a,f),e=Ce(a,k)?Fa(d,e,f.g):Ha(d,e,f.g),d=H(d,e),Fe(l,d),Oe(a,g,f.i,e)):(h.status=-1,a.i[h.i].g.delete(h.g),Fe(l,h),Be(a,d,g,e));await Ma(a,g,l.size);q&&q.length&&await Pa(a,g,0,q.length,q);if(Ce(a,g))for(const t of Pe(a,k))if(e=await Ra(a,k,t,g,t),0>
e)return e;await Ke(a,k);a=Ta(a,b,c);if(0>a)return a}else De(a,b,c),Be(a,d,g,e),h.za.version++;return 0}async function Pa(a,b,c,d,e){var g=a.g[b];if(5===g.status)b=g.g,await Pa(Z(a,g),b,c,d,e);else{var f=await a.pb(b);!f||f.length<c+d?(await Ma(a,b,Math.floor(3*(c+d)/2)),g.size=c+d,f=await a.pb(b)):g.size<c+d&&(g.size=c+d);e&&f.set(e.subarray(0,d),c);await Ie(a,b,f)}}async function Oa(a,b,c,d){const e=a.g[b];return 5===e.status?(b=e.g,await Oa(Z(a,e),b,c,d)):await Qe(a,b,c,d)}
function Sa(a,b,c){b=a.g[b];if(5===b.status){const d=b.g;c=Sa(Z(a,b),d,c);return-1===c?-1:Re(a,b.i,c)}a=b.ia.get(c);return void 0===a?-1:a}function xa(a){let b=a.g.length;for(const {h:c,g:d}of a.i)b+=xa(c),b-=d.size;return b}function za(a){let b=1048576;for(const {h:c}of a.i)b+=za(c);return b}function va(a){let b=a.o;for(const {h:c}of a.i)b+=va(c);return b}function wa(a){let b=a.l;for(const {h:c}of a.i)b+=wa(c);return a.l}
function Me(a,b){const c=a.g[Ne(a,b)];if(5===c.status)return Me(Z(a,c),a.g[b].g);if(!c)return"";for(const [d,e]of c.ia)if(e===b)return d;return""}function Ca(a,b,c,d){if(Ce(a,c))return-1;const e=a.g[b],g=a.g[c];if(5===e.status)return 5!==g.status||g.i!==e.i?-1:Ca(Z(a,e),e.g,g.g,d);if(5===g.status)return-1;Be(a,b,c,d);return 0}
function Ta(a,b,c){if("."===c||".."===c)return-1;var d=Sa(a,b,c);const e=a.g[d];var g=a.g[b];if(5===g.status)return b=g.g,Ta(Z(a,g),b,c);if(g=Ce(a,d)){a:if(d=a.g[d],5===d.status)var f=Ce(Z(a,d),d.g);else{for(f of d.ia.keys())if("."!==f&&".."!==f){f=!1;break a}f=!0}g=!f}if(g)return-39;De(a,b,c);0===e.Ua&&(e.status=La);return 0}async function Ke(a,b){const c=a.g[b];5===c.status?await Ke(Z(a,c),c.g):(c.size=0,delete a.h[b])}
we.prototype.pb=async function(a){const b=this.g[a];return this.h[a]?this.h[a]:2===b.status?await this.j.read(b.sd,0,b.size):null};async function Qe(a,b,c,d){const e=a.g[b];return a.h[b]?a.h[b].subarray(c,c+d):2===e.status?await a.j.read(e.sd,c,d):null}async function Ie(a,b,c){a.h[b]=c;2===a.g[b].status&&(a.g[b].status=0,a.j.g(a.g[b].sd))}function H(a,b){b=a.g[b];return 5===b.status?H(Z(a,b),b.g):b}
async function Ma(a,b,c){var d=H(a,b),e=await Qe(a,b,0,d.size);if(c!=d.size){var g=new Uint8Array(c);d.size=c;e&&g.set(e.subarray(0,Math.min(e.length,d.size)),0);await Ie(a,b,g)}}
function Se(a,b){b=b.replace("//","/");b=b.split("/");0<b.length&&0===b[b.length-1].length&&b.pop();0<b.length&&0===b[0].length&&b.shift();const c=b.length;var d=-1,e=0;let g=null;for(var f=0;f<c;f++)if(d=e,e=Sa(a,d,b[f]),!g&&5===a.g[d].status&&(g="/"+b.slice(f).join("/")),-1==e)return f<c-1?{id:-1,uf:-1,name:b[f],bg:g}:{id:-1,uf:d,name:b[f],bg:g};return{id:e,uf:d,name:b[f],bg:g}}
function Je(a,b){var c=a.g[b];if(5===c.status)Je(Z(a,c),c.g);else{var d=0;for(const e of c.ia.keys())d+=24+Te(e);b=a.h[b]=new Uint8Array(d);c.size=d;d=0;for(const [e,g]of c.ia)c=H(a,g),d+=v(["Q","d","b","s"],[c.za,d+13+8+1+2+Te(e),c.mode>>12,e],b,d)}}function Na(a,b,c){a=a.h[b];if(c>=a.length)return a.length;for(b=0;;){const d=E(["Q","d"],a,{offset:b})[1];if(d>c)break;b=d}return b}function Ce(a,b){b=a.g[b];return 5===b.status?Ce(Z(a,b),b.g):(b.mode&61440)===Ga}
function Pe(a,b){Ce(a,b);b=a.g[b];if(5===b.status)return Pe(Z(a,b),b.g);a=[];for(const c of b.ia.keys())"."!==c&&".."!==c&&a.push(c);return a}function Ne(a,b){Ce(a,b);b=a.g[b];if(5!==b.status||0===b.g)return b.ia.get("..");const c=Ne(Z(a,b),b.g);return Re(a,b.i,c)}function Oe(a,b,c,d){const e=a.g[b];5===e.status&&a.i[e.i].g.delete(e.g);e.status=5;e.i=c;e.g=d;a.i[c].g.set(d,b)}function Ge(a,b,c){const d=ze(a),e=a.g.length;a.g.push(d);d.dc=e;Oe(a,e,b,c);return e}
function Re(a,b,c){const d=a.i[b].g.get(c);return void 0===d?Ge(a,b,c):d}function Z(a,b){return a.i[b.i].h}function Ee(){this.type=2;this.start=0;this.length=Infinity;this.h=-1;this.g=""}Ee.prototype.$=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.h;a[4]=this.g;return a};Ee.prototype.H=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.h=a[3];this.g=a[4]};function Ue(a){const b=new Ee;b.H(a.$());return b}
function Ve(a,b){return b.h===a.h&&b.g===a.g&&b.type===a.type}function We(a,b){return Ve(a,b)&&b.start+b.length===a.start}function Ia(a,b,c,d,e){const g=new Ee;g.type=a;g.start=b;g.length=c;g.h=d;g.g=e;return g}function Ka(a,b,c){b=a.g[b];if(5===b.status){var d=b.g;return Ka(Z(a,b),d,c)}for(d of b.h)if(!(c.h===d.h&&c.g===d.g||2===c.type||2===d.type||1!==c.type&&1!==d.type||c.start+c.length<=d.start||d.start+d.length<=c.start))return Ue(d);return null}
function Ja(a,b,c,d){const e=a.g[b];if(5===e.status)return b=e.g,Ja(Z(a,e),b,c,d);c=Ue(c);if(2!==c.type&&Ka(a,b,c))return 1;for(a=0;a<e.h.length;a++){d=e.h[a];if(d.start+d.length<=c.start)continue;if(c.start+c.length<=d.start)break;if(d.h!==c.h||d.g!==c.g)continue;b=c.start+c.length;const g=c.start-d.start,f=d.start+d.length-b;if(0<g&&0<f&&d.type===c.type)return 0;0<g&&(d.length=g);if(0>=g&&0<f)d.start=b,d.length=f;else if(0<f){for(;a<e.h.length&&e.h[a].start<b;)a++;e.h.splice(a,0,Ia(d.type,b,f,d.h,
d.g))}else 0>=g&&(e.h.splice(a,1),a--)}if(2!==c.type){a=c;d=!1;for(b=0;b<e.h.length&&!(We(a,e.h[b])&&(e.h[b].length+=c.length,a=e.h[b],d=!0),c.start<=e.h[b].start);b++);d||(e.h.splice(b,0,a),b++);for(;b<e.h.length;b++)if(Ve(e.h[b],a)){We(e.h[b],a)&&(a.length+=e.h[b].length,e.h.splice(b,1));break}}return 0}function Xe(a,b){b=Se(a,b);if(-1!==b.id)return a=H(a,b.id),Array.from(a.ia.keys()).filter(c=>"."!==c&&".."!==c)}
we.prototype.re=function(a){a=Se(this,a);if(-1===a.id)return Promise.resolve(null);const b=H(this,a.id);return Oa(this,a.id,0,b.size)};function v(a,b,c,d){for(var e,g=0,f=0;f<a.length;f++)switch(e=b[f],a[f]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;g+=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;g+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;g+=2;break;case "b":c[d++]=e;g+=1;break;case "s":var h=d,k=0;c[d++]=0;c[d++]=0;g+=2;for(var l of e)Ye(l.charCodeAt(0)).forEach(function(q){c[d++]=q;g+=1;k++});c[h+0]=k&255;c[h+1]=k>>8&255;break;
case "Q":v(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,g+=13}return g}
function E(a,b,c){let d=c.offset;for(var e=[],g=0;g<a.length;g++)switch(a[g]){case "w":var f=b[d++];f+=b[d++]<<8;f+=b[d++]<<16;f+=b[d++]<<24>>>0;e.push(f);break;case "d":f=b[d++];f+=b[d++]<<8;f+=b[d++]<<16;f+=b[d++]<<24>>>0;d+=4;e.push(f);break;case "h":f=b[d++];e.push(f+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":f=b[d++];f+=b[d++]<<8;for(var h="",k=new Ze,l=0;l<f;l++){var q=k.i(b[d++]);-1!=q&&(h+=String.fromCharCode(q))}e.push(h);break;case "Q":c.offset=d,f=E(["b","w","d"],b,c),d=
c.offset,e.push({type:f[0],version:f[1],path:f[2]})}c.offset=d;return e};function Ze(){this.g=new Uint8Array(5);this.h=0;this.i=function(a){this.g[this.h]=a;this.h++;switch(this.h){case 1:if(128>this.g[0])return this.h=0,this.g[0];break;case 2:if(192==(this.g[0]&224)&&128==(this.g[1]&192))return this.h=0,(this.g[0]&31)<<6|this.g[1]&63}return-1}}function Ye(a){if(128>a)return[a];if(2048>a)return[192|a>>6&31,128|a&63]}function Te(a){for(var b=0,c=0;c<a.length;c++)b+=128>a.charCodeAt(c)?1:2;return b};function $e(a){function b(m){!m.altKey&&h[56]&&g(56,!1);return e(m,!1)}function c(m){!m.altKey&&h[56]&&g(56,!1);return e(m,!0)}function d(){for(var m=Object.keys(h),r,x=0;x<m.length;x++)r=+m[x],h[r]&&g(r,!1);h={}}function e(m,r){if(k.v&&(m.shiftKey&&m.ctrlKey&&(73===m.keyCode||74===m.keyCode||75===m.keyCode)||!k.Ie?0:m.target?m.target.classList.contains("phone_keyboard")||"INPUT"!==m.target.nodeName&&"TEXTAREA"!==m.target.nodeName:1)){a:{if(void 0!==m.code){var x=t[m.code];if(void 0!==x)break a}x=
l[m.keyCode]}if(x)return g(x,r,m.repeat),m.preventDefault&&m.preventDefault(),!1;console.log("Missing char in map: keyCode="+(m.keyCode||-1).toString(16)+" code="+m.code)}}function g(m,r,x){if(r)h[m]&&!x&&g(m,!1);else if(!h[m])return;(h[m]=r)||(m|=128);255<m?(f(m>>8),f(m&255)):f(m)}function f(m){k.v.send("keyboard-code",m)}var h={},k=this;this.Ie=!0;var l=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,
82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),q={8:8,10:13,32:32,39:222,
44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},n={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,
81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192},t={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,
Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,
Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.v=a;this.va=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",b,!1),window.removeEventListener("keydown",c,!1),window.removeEventListener("blur",d,!1))};this.hb=function(){"undefined"!==typeof window&&(this.va(),window.addEventListener("keyup",b,!1),window.addEventListener("keydown",c,
!1),window.addEventListener("blur",d,!1))};this.hb();this.g=function(m){m={keyCode:m};e(m,!0);e(m,!1)};this.Jj=function(m){var r=m.charCodeAt(0);r in q?this.g(q[r]):r in n?(f(42),this.g(n[r]),f(170)):console.log("ascii -> keyCode not found: ",r,m)}};function af(a,b){function c(w){if(!x.enabled||!x.Ie)return!1;var A=b||document.body,I;if(!(I=document.pointerLockElement))a:{for(w=w.target;w.parentNode;){if(w===A){I=!0;break a}w=w.parentNode}I=!1}return I}function d(w){c(w)&&(w=w.changedTouches)&&w.length&&(w=w[w.length-1],m=w.clientX,r=w.clientY)}function e(){if(q||t||n)x.v.send("mouse-click",[!1,!1,!1]),q=t=n=!1}function g(w){if(x.v&&c(w)&&x.Zc){var A=0,I=0,O=w.changedTouches;O?O.length&&(O=O[O.length-1],A=O.clientX-m,I=O.clientY-r,m=O.clientX,
r=O.clientY,w.preventDefault()):"number"===typeof w.movementX?(A=w.movementX,I=w.movementY):"number"===typeof w.webkitMovementX?(A=w.webkitMovementX,I=w.webkitMovementY):"number"===typeof w.mozMovementX?(A=w.mozMovementX,I=w.mozMovementY):(A=w.clientX-m,I=w.clientY-r,m=w.clientX,r=w.clientY);x.v.send("mouse-delta",[.15*A,-(.15*I)]);b&&x.v.send("mouse-absolute",[w.pageX-b.offsetLeft,w.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function f(w){c(w)&&k(w,!0)}function h(w){c(w)&&k(w,!1)}function k(w,
A){x.v&&(1===w.which?q=A:2===w.which?t=A:3===w.which&&(n=A),x.v.send("mouse-click",[q,t,n]),w.preventDefault())}function l(w){if(c(w)){var A=w.wheelDelta||-w.detail;0>A?A=-1:0<A&&(A=1);x.v.send("mouse-wheel",[A,0]);w.preventDefault()}}var q=!1,n=!1,t=!1,m=0,r=0,x=this;this.enabled=!1;this.Ie=!0;this.v=a;this.v.register("mouse-enable",function(w){this.enabled=w},this);this.Zc=!1;this.v.register("emulator-stopped",function(){this.Zc=!1},this);this.v.register("emulator-started",function(){this.Zc=!0},
this);this.va=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",g,!1),window.removeEventListener("mousemove",g,!1),window.removeEventListener("mousedown",f,!1),window.removeEventListener("mouseup",h,!1),window.removeEventListener("wheel",l,{passive:!1}))};this.hb=function(){"undefined"!==typeof window&&(this.va(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",
e,!1),window.addEventListener("touchmove",g,!1),window.addEventListener("mousemove",g,!1),window.addEventListener("mousedown",f,!1),window.addEventListener("mouseup",h,!1),window.addEventListener("wheel",l,{passive:!1}))};this.hb()};function bf(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?cf:df;this.v=a;this.U=window.AudioContext?new AudioContext:new webkitAudioContext;this.Qe=new ef(a,this.U);this.h=new ff(a,this.U,this.Qe);this.g=new b(a,this.U,this.Qe);this.h.start();a.register("emulator-stopped",function(){this.U.suspend()},this);a.register("emulator-started",function(){this.U.resume()},this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},
this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}bf.prototype.va=function(){this.U&&this.U.close();this.g&&this.g.Jb&&this.g.Jb.port.close()};
function ef(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.U.currentTime)}}this.U=b;this.sources=new Map;this.eg=this.dg=this.F=this.D=this.B=1;this.i=this.U.createBiquadFilter();this.j=this.U.createBiquadFilter();this.i.type="highshelf";this.j.type="highshelf";this.i.frequency.setValueAtTime(2E3,this.U.currentTime);this.j.frequency.setValueAtTime(2E3,this.U.currentTime);this.g=this.U.createBiquadFilter();this.h=this.U.createBiquadFilter();this.g.type="lowshelf";this.h.type="lowshelf";
this.g.frequency.setValueAtTime(200,this.U.currentTime);this.h.frequency.setValueAtTime(200,this.U.currentTime);this.l=this.U.createGain();this.o=this.U.createGain();this.C=this.U.createChannelMerger(2);this.J=this.i;this.L=this.j;this.i.connect(this.g);this.g.connect(this.l);this.l.connect(this.C,0,0);this.j.connect(this.h);this.h.connect(this.o);this.o.connect(this.C,0,1);this.C.connect(this.U.destination);a.register("mixer-connect",function(d){var e=d[1];d=this.sources.get(d[0]);void 0===d||d.connect(e)},
this);a.register("mixer-disconnect",function(d){var e=d[1];d=this.sources.get(d[0]);void 0===d||d.disconnect(e)},this);a.register("mixer-volume",function(d){var e=d[0],g=d[1];d=Math.pow(10,d[2]/20);e=0===e?this:this.sources.get(e);void 0===e||e.af(d,g)},this);a.register("mixer-gain-left",function(d){this.dg=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.eg=Math.pow(10,d/20);this.update()},this);a.register("mixer-treble-left",c(this.i),this);a.register("mixer-treble-right",
c(this.j),this);a.register("mixer-bass-left",c(this.g),this);a.register("mixer-bass-right",c(this.h),this)}function gf(a,b,c){b=new hf(a.U,b,a.J,a.L);a.sources.has(c);a.sources.set(c,b);return b}ef.prototype.af=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.D=a;break;case 1:this.F=a;break;case 2:this.B=a;break;default:return}this.update()};
ef.prototype.update=function(){var a=this.B*this.F*this.eg;this.l.gain.setValueAtTime(this.B*this.D*this.dg,this.U.currentTime);this.o.gain.setValueAtTime(a,this.U.currentTime)};function hf(a,b,c,d){this.U=a;this.o=this.l=!0;this.D=this.C=this.j=this.g=1;this.B=a.createChannelSplitter(2);this.h=a.createGain();this.i=a.createGain();b.connect(this.B);this.B.connect(this.h,0);this.h.connect(c);this.B.connect(this.i,1);this.i.connect(d)}
hf.prototype.update=function(){var a=this.o*this.g*this.j*this.D;this.h.gain.setValueAtTime(this.l*this.g*this.j*this.C,this.U.currentTime);this.i.gain.setValueAtTime(a,this.U.currentTime)};hf.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.l=!0;if(b||1===a)this.o=!0;this.update()};hf.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.l=!1;if(b||1===a)this.o=!1;this.update()};
hf.prototype.af=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.C=a;break;case 1:this.D=a;break;case 2:this.j=a;break;default:return}this.update()};
function ff(a,b,c){this.Jd=b.createOscillator();this.Jd.type="square";this.Jd.frequency.setValueAtTime(440,b.currentTime);this.g=gf(c,this.Jd,1);this.g.disconnect();a.register("pcspeaker-enable",function(){var d=c.sources.get(1);void 0===d||d.connect(void 0)},this);a.register("pcspeaker-disable",function(){var d=c.sources.get(1);void 0===d||d.disconnect(void 0)},this);a.register("pcspeaker-update",function(d){var e=d[1],g=0;3===d[0]&&(g=Math.min(1193181.6665999999/e,this.Jd.frequency.maxValue),g=
Math.max(g,0));this.Jd.frequency.setValueAtTime(g,b.currentTime)},this)}ff.prototype.start=function(){this.Jd.start()};
function cf(a,b,c){this.v=a;this.U=b;this.enabled=!1;this.Ya=48E3;b=function(){function e(h){if(0===h)return 1;h*=Math.PI;return Math.sin(h)/h}function g(){var h=Reflect.construct(AudioWorkletProcessor,[],g);h.D=3;h.l=Array(1024);h.B=0;h.J=0;h.o=0;h.F=h.l.length;h.C=0;h.L=f;h.g=f;h.O=1;h.j=0;h.i=0;h.h=0;h.port.onmessage=k=>{switch(k.data.type){case "queue":h.ba(k.data.value);break;case "sampling-rate":h.O=k.data.value/sampleRate}};return h}var f=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(g.prototype,
AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(g,AudioWorkletProcessor);g.prototype.process=g.prototype.process=function(h,k){for(h=0;h<k[0][0].length;h++){for(var l=0,q=0,n=this.h+this.D,t=this.h-this.D+1;t<=n;t++){var m=this.j+t;l+=this.P(m,0)*this.T(this.i-t);q+=this.P(m,1)*this.T(this.i-t)}if(isNaN(l)||isNaN(q))l=q=0;k[0][0][h]=l;k[0][1][h]=q;this.i+=this.O;this.h=Math.floor(this.i)}k=this.h;k+=this.D+2;this.i-=this.h;this.j+=this.h;this.h=0;this.X(k);return!0};g.prototype.T=function(h){return e(h)*
e(h/this.D)};g.prototype.P=function(h,k){return 0>h?(h+=this.L[0].length,this.L[k][h]):this.g[k][h]};g.prototype.X=function(h){var k=this.g[0].length;k-this.j<h&&(this.Y(),this.j-=k)};g.prototype.Y=function(){this.L=this.g;this.g=this.V();var h=this.g[0].length;if(256>h){for(var k=this.B,l=0;256>h&&l<this.o;)h+=this.l[k][0].length,k=k+1&this.F-1,l++;h=Math.max(h,256);h=[new Float32Array(h),new Float32Array(h)];h[0].set(this.g[0]);h[1].set(this.g[1]);k=this.g[0].length;for(var q=0;q<l;q++){var n=this.V();
h[0].set(n[0],k);h[1].set(n[1],k);k+=n[0].length}this.g=h}this.lc()};g.prototype.lc=function(){1024>this.C/this.O&&this.port.postMessage({type:"pump"})};g.prototype.ba=function(h){this.o<this.F&&(this.l[this.J]=h,this.J=this.J+1&this.F-1,this.o++,this.C+=h[0].length,this.lc())};g.prototype.V=function(){if(!this.o)return f;var h=this.l[this.B];this.l[this.B]=null;this.B=this.B+1&this.F-1;this.o--;this.C-=h[0].length;return h};registerProcessor("dac-processor",g)}.toString();var d=URL.createObjectURL(new Blob([b.substring(b.indexOf("{")+
1,b.lastIndexOf("}"))],{type:"application/javascript"}));this.Jb=null;this.g=this.U.createGain();this.U.audioWorklet.addModule(d).then(()=>{URL.revokeObjectURL(d);this.Jb=new AudioWorkletNode(this.U,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.Jb.port.postMessage({type:"sampling-rate",value:this.Ya});this.Jb.port.onmessage=e=>{switch(e.data.type){case "pump":this.lc()}};this.Jb.connect(this.g)});this.h=gf(c,this.g,2);this.h.g=
3;a.register("dac-send-data",function(e){this.yf(e)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(e){this.Ya=e;this.Jb&&this.Jb.port.postMessage({type:"sampling-rate",value:e})},this)}cf.prototype.yf=function(a){this.Jb&&this.Jb.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};cf.prototype.lc=function(){this.enabled&&this.v.send("dac-request-data")};
function df(a,b,c){this.v=a;this.U=b;this.enabled=!1;this.Ya=22050;this.g=0;this.pe=1;this.Se=this.U.createBiquadFilter();this.Se.type="lowpass";this.i=this.Se;this.h=gf(c,this.i,2);this.h.g=3;a.register("dac-send-data",function(d){this.yf(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.lc()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){this.Ya=d;this.pe=Math.ceil(8E3/d);this.Se.frequency.setValueAtTime(d/2,this.U.currentTime)},
this)}
df.prototype.yf=function(a){var b=a[0].length,c=b/this.Ya;if(1<this.pe){var d=this.U.createBuffer(2,b*this.pe,this.Ya*this.pe);for(var e=d.getChannelData(0),g=d.getChannelData(1),f=0,h=0;h<b;h++)for(var k=0;k<this.pe;k++,f++)e[f]=a[0][h],g[f]=a[1][h]}else d=this.U.createBuffer(2,b,this.Ya),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.U.createBufferSource();a.buffer=d;a.connect(this.Se);a.addEventListener("ended",this.lc.bind(this));
d=this.U.currentTime;if(this.g<d)for(this.g=d,d=.2-c,b=0;b<=d;)b+=c,this.g+=c,setTimeout(()=>this.lc(),1E3*b);a.start(this.g);this.g+=c;setTimeout(()=>this.lc(),0)};df.prototype.lc=function(){this.enabled&&(.2<this.g-this.U.currentTime||this.v.send("dac-request-data"))};function jf(a,b){function c(h){f.v&&f.enabled&&(f.h(h.which),h.preventDefault())}function d(h){var k=h.which;8===k?(f.h(127),h.preventDefault()):9===k&&(f.h(9),h.preventDefault())}function e(h){if(f.enabled){for(var k=h.clipboardData.getData("text/plain"),l=0;l<k.length;l++)f.h(k.charCodeAt(l));h.preventDefault()}}function g(h){h.target!==a&&a.blur()}var f=this;this.enabled=!0;this.v=b;this.text="";this.j=!1;this.i=0;this.v.register("serial0-output-char",function(h){this.Ij(h)},this);this.va=function(){a.removeEventListener("keypress",
c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",g,!1)};this.hb=function(){this.va();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",g,!1)};this.hb();this.Ij=function(h){"\b"===h?(this.text=this.text.slice(0,-1),this.update()):"\r"!==h&&(this.text+=h,"\n"===h&&(this.j=!0),this.update())};this.update=function(){var h=
Date.now(),k=h-this.i;16>k?void 0===this.g&&(this.g=setTimeout(()=>{this.g=void 0;this.i=Date.now();this.l()},16-k)):(void 0!==this.g&&(clearTimeout(this.g),this.g=void 0),this.i=h,this.l())};this.l=function(){a.value=this.text;this.j&&(this.j=!1,a.scrollTop=1E9)};this.h=function(h){f.v&&f.v.send("serial0-input",h)}}
function kf(a,b){this.element=a;if(window.Terminal){var c=this.g=new window.Terminal;c.setOption("logLevel","off");c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let g=0;g<e.length;g++)b.send("serial0-input",e.charCodeAt(g))});b.register("serial0-output-char",function(e){c.write(e)},this);this.va=function(){d.dispose();c.dispose()}}}kf.prototype.show=function(){this.g&&this.g.open(this.element)};function lf(a,b){this.v=b;this.g=void 0;this.h=[];this.url=a;this.i=Date.now()-1E4;this.v.register("net0-send",function(c){this.send(c)},this)}p=lf.prototype;p.Mh=function(a){this.v&&this.v.send("net0-receive",new Uint8Array(a.data))};p.Kh=function(){this.connect();setTimeout(this.connect.bind(this),1E4)};p.Nh=function(){for(var a=0;a<this.h.length;a++)this.send(this.h[a]);this.h=[]};p.Lh=function(){};p.va=function(){this.g&&this.g.close()};
p.connect=function(){if("undefined"!==typeof WebSocket){if(this.g){var a=this.g.readyState;if(0===a||1===a)return}this.i+1E4>Date.now()||(this.i=Date.now(),this.g=new WebSocket(this.url),this.g.binaryType="arraybuffer",this.g.onopen=this.Nh.bind(this),this.g.onmessage=this.Mh.bind(this),this.g.onclose=this.Kh.bind(this),this.g.onerror=this.Lh.bind(this))}};p.send=function(a){this.g&&1===this.g.readyState?this.g.send(a):(this.h.push(a),128<this.h.length&&(this.h=this.h.slice(-64)),this.connect())};function Xa(a){this.Ge=!1;var b=ce();this.v=b[0];this.Gd=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:f=>this.cpu_exception_hook&&this.cpu_exception_hook(f),hlt_op:function(){var f=c;0===(f.o()&512)&&f.v.send("cpu-event-halt");f.h[0]=1;mb(f)},abort:function(){},microtick:nb,get_rand_int:function(){return zb()},pic_acknowledge:function(){me(c)},io_port_read8:function(f){f=c.A.ports[f];return f.od.call(f.oa)},io_port_read16:function(f){f=c.A.ports[f];
return f.Oa.call(f.oa)},io_port_read32:function(f){f=c.A.ports[f];return f.qe.call(f.oa)},io_port_write8:function(f,h){f=c.A.ports[f];f.df.call(f.oa,h)},io_port_write16:function(f,h){f=c.A.ports[f];f.Ae.call(f.oa,h)},io_port_write32:function(f,h){f=c.A.ports[f];f.Lc.call(f.oa,h)},mmap_read8:function(f){return c.i[f>>>17](f)},mmap_read16:function(f){var h=c.i[f>>>17];return h(f)|h(f+1|0)<<8},mmap_read32:function(f){return c.pa[f>>>17](f)},mmap_write8:function(f,h){c.l[f>>>17](f,h)},mmap_write16:function(f,
h){var k=c.l[f>>>17];k(f,h&255);k(f+1|0,h>>8)},mmap_write32:function(f,h){c.j[f>>>17](f,h)},mmap_write64:function(f,h,k){var l=c.j[f>>>17];l(f,h);l(f+4,k)},mmap_write128:function(f,h,k,l,q){var n=c.j[f>>>17];n(f,h);n(f+4,k);n(f+8,l);n(f+12,q)},log_from_wasm:function(f,h){[...(new Uint8Array(d.buffer,f>>>0,h>>>0))]},console_log_from_wasm:function(f,h){f=String.fromCharCode(...(new Uint8Array(d.buffer,f>>>0,h>>>0)));console.error(f)},dbg_trace_from_wasm:function(){},codegen_finalize:(f,h,k,l,q)=>{le(c,
f,h,k,l,q)},jit_clear_func:f=>{c.xa.Mf.set(f+1024,null)},jit_clear_all_funcs:()=>{const f=c.xa.Mf;for(let h=0;900>h;h++)f.set(1024+h,null)},__indirect_function_table:e};let g=a.wasm_fn;g||(g=f=>new Promise(h=>{let k="v86.wasm",l="v86-fallback.wasm";if(a.wasm_path){k=a.wasm_path;const q=k.lastIndexOf("/");l=(-1===q?"":k.substr(0,q))+"/"+l}else"undefined"===typeof window&&"string"===typeof __dirname?(k=__dirname+"/"+k,l=__dirname+"/"+l):(k="build/"+k,l="build/"+l);Gb(k,{done:async q=>{try{const {instance:n}=
await WebAssembly.instantiate(q,f);this.D=q;h(n.exports)}catch(n){Gb(l,{done:async t=>{const {instance:m}=await WebAssembly.instantiate(t,f);this.D=t;h(m.exports)}})}},progress:q=>{this.Gd.send("download-progress",{ge:0,fe:1,he:k,lengthComputable:q.lengthComputable,total:q.total,loaded:q.loaded})}})}));g({env:b}).then(f=>{d=f.memory;f.rust_init();f=this.g=new ib(this.Gd,{exports:f,Mf:e});c=f.s;mf(this,f,a)});this.i=null;this.F=0}
async function mf(a,b,c){function d(m,r){switch(m){case "hda":g.M=this.ac.hda=r;break;case "hdb":g.Ke=this.ac.hdb=r;break;case "cdrom":g.ga=this.ac.cdrom=r;break;case "fda":g.ma=this.ac.fda=r;break;case "fdb":g.Zf=this.ac.fdb=r;break;case "multiboot":g.ed=this.ac.multiboot=r.buffer;break;case "bzimage":g.vb=this.ac.bzimage=r.buffer;break;case "initrd":g.Xc=this.ac.initrd=r.buffer;break;case "bios":g.Bd=r.buffer;break;case "vga_bios":g.Sj=r.buffer;break;case "initial_state":g.Wc=r.buffer;break;case "fs9p_json":g.cg=
r}}async function e(){if(g.Db&&g.cg){if(!g.Wc){var m=g.Db,r=g.cg;if(3!==r.version)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";var x=r.fsroot;m.o=r.size;for(r=0;r<x.length;r++)ye(m,x[r],0)}if(c.bzimage_initrd_from_filesystem){const {kh:w,Sh:A}=nf(g.Db),[I,O]=await Promise.all([g.Db.re(A),g.Db.re(w)]);d.call(this,"initrd",new tb(I.buffer));d.call(this,"bzimage",new tb(O.buffer))}}this.Qd&&this.Qd.show&&
this.Qd.show();this.v.send("cpu-init",g);g.Wc&&(b.Nd(g.Wc),g.Wc=void 0);c.autostart&&this.v.send("cpu-run");this.Gd.send("emulator-loaded")}a.v.register("emulator-stopped",function(){this.Ge=!1},a);a.v.register("emulator-started",function(){this.Ge=!0},a);var g={};a.ac={fda:void 0,fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};g.ya=c.acpi;g.Vh=!0;g.wk=c.log_level;g.G=c.memory_size||67108864;g.ha=c.vga_memory_size||8388608;g.oc=c.boot_order||531;g.Hh=c.fastboot||!1;g.ma=void 0;g.Zf=void 0;g.ve=c.uart1;
g.we=c.uart2;g.xe=c.uart3;g.Pc=c.cmdline;g.vf=c.preserve_mac_from_state_image;g.Gb=c.mac_address_translation;g.Dd=c.cpuid_level;c.network_adapter?a.C=c.network_adapter(a.v):c.network_relay_url&&(a.C=new lf(c.network_relay_url,a.v));g.Fh=!0;c.disable_keyboard||(a.B=new $e(a.v));c.disable_mouse||(a.l=new af(a.v,c.screen_container));c.screen_container?a.h=new Va(c.screen_container,a.v):c.screen_dummy&&(a.h=new of(a.v));c.serial_container&&(a.Qd=new jf(c.serial_container,a.v));c.serial_container_xtermjs&&
(a.Qd=new kf(c.serial_container_xtermjs,a.v));c.disable_speaker||(a.j=new bf(a.v));var f=[],h=(m,r)=>{if(r)if(r.get&&r.set&&r.load)f.push({name:m,bd:r});else{if("bios"===m||"vga_bios"===m||"initial_state"===m||"multiboot"===m||"bzimage"===m||"initrd"===m)r.async=!1;r.buffer instanceof ArrayBuffer?(r=new tb(r.buffer),f.push({name:m,bd:r})):"undefined"!==typeof File&&r.buffer instanceof File?(void 0===r.async&&(r.async=268435456<=r.buffer.size),r=r.async?new wb(r.buffer):new db(r.buffer),f.push({name:m,
bd:r})):r.url&&(r.async?(r=r.aa?new vb(r.url,r.size,r.I,!1,a.Yj.bind(a)):new ub(r.url,r.size,r.I),f.push({name:m,bd:r})):f.push({name:m,url:r.url,size:r.size}))}};c.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");for(var k="bios vga_bios cdrom hda hdb fda fdb initial_state multiboot bzimage initrd".split(" "),l=0;l<k.length;l++)h(k[l],c[k[l]]);if(c.filesystem&&(h=c.filesystem.ih,k=c.filesystem.Ce,l=new pf,k&&(l=new qf(l,k)),g.Db=a.Db=new we(l),h)){if("object"===
typeof h){var q=h.size;h=h.url}f.push({name:"fs9p_json",url:h,size:q,zd:!0})}var n=f.length,t=function(m){if(m===n)setTimeout(e.bind(this),0);else{var r=f[m];r.bd?(r.bd.onload=function(){d.call(this,r.name,r.bd);t(m+1)}.bind(this),r.bd.load()):Gb(r.url,{done:function(x){if(r.url.endsWith(".zst")&&"initial_state"!==r.name){var w=r.size,A=new Uint8Array(x);x=this.g.s;this.o=x.Tg(A.length);(new Uint8Array(x.Ja.buffer)).set(A,x.Vg(this.o));A=x.Td(this.o,w);const I=x.Ja.buffer.slice(A,A+w);x.Ud(A,w);x.Ug(this.o);
this.o=null;x=I}d.call(this,r.name,r.zd?x:new tb(x));t(m+1)}.bind(this),progress:function(x){200===x.target.status?a.Gd.send("download-progress",{ge:m,fe:n,he:r.url,lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):a.Gd.send("download-error",{ge:m,fe:n,he:r.url,request:x.target})},zd:r.zd})}}.bind(a);t(0)}p=Xa.prototype;
p.Yj=async function(a,b){if(!this.i){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var g=e.data.src,f=e.data.uh;e=e.data.id;var h=d.exports,k=h.zstd_create_ctx(g.length);(new Uint8Array(h.memory.buffer)).set(g,h.zstd_get_src_ptr(k));g=h.zstd_read(k,f);var l=h.memory.buffer.slice(g,g+f);h.zstd_read_free(g,f);h.zstd_free_ctx(k);postMessage({result:l,id:e},[l])}else f=Object.fromEntries("cpu_exception_hook hlt_op microtick get_rand_int pic_acknowledge io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(q=>
[q,()=>console.error("zstd worker unexpectedly called "+q)])),f.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),f.abort=()=>{throw Error("zstd worker aborted");},f.log_from_wasm=f.console_log_from_wasm=(q,n)=>{console.log(String.fromCharCode(...(new Uint8Array(d.exports.memory.buffer,q,n))))},f.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:f})}}.toString()+")()"],{type:"text/javascript"}));this.i=new Worker(c);
URL.revokeObjectURL(c);this.i.postMessage(this.D,[this.D])}return new Promise(c=>{const d=this.F++,e=async g=>{g.data.id===d&&(this.i.removeEventListener("message",e),c(g.data.result))};this.i.addEventListener("message",e);this.i.postMessage({src:b,uh:a,id:d},[b.buffer])})};
function nf(a){const b=(Xe(a,"/")||[]).map(e=>"/"+e);a=(Xe(a,"/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(let e of[].concat(b,a)){const g=/old/i.test(e)||/fallback/i.test(e),f=/initrd/i.test(e)||/initramfs/i.test(e);!/vmlinuz/i.test(e)&&!/bzimage/i.test(e)||d&&g||(d=e);!f||c&&g||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{Sh:c,kh:d}}p.Ze=async function(){this.v.send("cpu-run")};
p.stop=async function(){this.Ge&&await new Promise(a=>{const b=()=>{this.v.unregister("emulator-stopped",b);a()};J(this,"emulator-stopped",b);this.v.send("cpu-stop")})};p.va=async function(){await this.stop();this.g.va();this.B&&this.B.va();this.C&&this.C.va();this.l&&this.l.va();this.h&&this.h.va();this.Qd&&this.Qd.va();this.j&&this.j.va()};p.zf=function(){this.v.send("cpu-restart")};function J(a,b,c){a.v.register(b,c,a)}p.Nd=async function(a){this.g.Nd(a)};p.se=async function(){return this.g.se()};
p.Zc=function(){return this.Ge};function Za(a,b){for(var c=0;c<b.length;c++)a.v.send("keyboard-code",b[c])}function Wa(a,b){for(var c=0;c<b.length;c++)a.B.Jj(b[c])}function cb(){var a=document.body,b=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock;b&&b.call(a)}p.qh=async function(a,b){var c=this.Db;if(c){var d=a.split("/");d=d[d.length-1];a=Se(c,a).uf;if(""!==d&&-1!==a)await He(c,d,a,b);else return Promise.reject(new rf)}};
p.re=async function(a){var b=this.Db;if(b)return(a=await b.re(a))?a:Promise.reject(new rf)};function rf(){this.message="File not found"}rf.prototype=Error.prototype;"undefined"!==typeof window?(window.V86Starter=Xa,window.V86=Xa):"undefined"!==typeof module&&"undefined"!==typeof module.exports?(module.exports.V86Starter=Xa,module.exports.V86=Xa):"function"===typeof importScripts&&(self.V86Starter=Xa,self.V86=Xa);function of(a){var b,c,d,e,g;this.v=a;a.register("screen-set-mode",function(f){this.Df(f)},this);a.register("screen-fill-buffer-end",function(f){this.Kf(f[0])},this);a.register("screen-put-char",function(f){this.xf(f[0],f[1],f[2],f[3],f[4])},this);a.register("screen-text-scroll",function(f){console.log("scroll",f)},this);a.register("screen-update-cursor",function(f){this.wd(f[0],f[1])},this);a.register("screen-update-cursor-scanline",function(f){this.xd(f[0],f[1])},this);a.register("screen-set-size-text",
function(f){this.rd(f[0],f[1])},this);a.register("screen-set-size-graphical",function(f){this.qd(f[0],f[1])},this);this.xf=function(f,h,k,l,q){f<g&&h<e&&(f=3*(f*e+h),d[f]=k,d[f+1]=l,d[f+2]=q)};this.va=function(){};this.Df=function(){};this.Sf=function(){};this.rd=function(f,h){if(f!==e||h!==g)d=new Int32Array(f*h*3),e=f,g=h};this.qd=function(){};this.Ef=function(){};this.xd=function(){};this.wd=function(f,h){if(f!==b||h!==c)b=f,c=h};this.Kf=function(){}};const Ya={Lj:function(a){return Ya.Cj(a)+Ya.Bj(a)},Cj:function(a){let b="";var c="COMPILE COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_WRONG_ADDRESS_SPACE COMPILE_CUT_OFF_AT_END_OF_PAGE COMPILE_WITH_LOOP_SAFETY COMPILE_PAGE COMPILE_PAGE/COMPILE COMPILE_BASIC_BLOCK COMPILE_DUPLICATED_BASIC_BLOCK COMPILE_WASM_BLOCK COMPILE_WASM_LOOP COMPILE_DISPATCHER COMPILE_ENTRY_POINT COMPILE_WASM_TOTAL_BYTES COMPILE_WASM_TOTAL_BYTES/COMPILE_PAGE RUN_INTERPRETED RUN_INTERPRETED_NEW_PAGE RUN_INTERPRETED_PAGE_HAS_CODE RUN_INTERPRETED_PAGE_HAS_ENTRY_AFTER_PAGE_WALK RUN_INTERPRETED_NEAR_END_OF_PAGE RUN_INTERPRETED_DIFFERENT_STATE RUN_INTERPRETED_DIFFERENT_STATE_CPL3 RUN_INTERPRETED_DIFFERENT_STATE_FLAT RUN_INTERPRETED_DIFFERENT_STATE_IS32 RUN_INTERPRETED_DIFFERENT_STATE_SS32 RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED RUN_INTERPRETED_STEPS RUN_FROM_CACHE RUN_FROM_CACHE_STEPS RUN_FROM_CACHE_STEPS/RUN_FROM_CACHE RUN_FROM_CACHE_STEPS/RUN_INTERPRETED_STEPS DIRECT_EXIT INDIRECT_JUMP INDIRECT_JUMP_NO_ENTRY NORMAL_PAGE_CHANGE NORMAL_FALLTHRU NORMAL_FALLTHRU_WITH_TARGET_BLOCK NORMAL_BRANCH NORMAL_BRANCH_WITH_TARGET_BLOCK CONDITIONAL_JUMP CONDITIONAL_JUMP_PAGE_CHANGE CONDITIONAL_JUMP_EXIT CONDITIONAL_JUMP_FALLTHRU CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK CONDITIONAL_JUMP_BRANCH CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK DISPATCHER_SMALL DISPATCHER_LARGE LOOP LOOP_SAFETY CONDITION_OPTIMISED CONDITION_UNOPTIMISED CONDITION_UNOPTIMISED_PF CONDITION_UNOPTIMISED_UNHANDLED_L CONDITION_UNOPTIMISED_UNHANDLED_LE FAILED_PAGE_CHANGE SAFE_READ_FAST SAFE_READ_SLOW_PAGE_CROSSED SAFE_READ_SLOW_NOT_VALID SAFE_READ_SLOW_NOT_USER SAFE_READ_SLOW_IN_MAPPED_RANGE SAFE_WRITE_FAST SAFE_WRITE_SLOW_PAGE_CROSSED SAFE_WRITE_SLOW_NOT_VALID SAFE_WRITE_SLOW_NOT_USER SAFE_WRITE_SLOW_IN_MAPPED_RANGE SAFE_WRITE_SLOW_READ_ONLY SAFE_WRITE_SLOW_HAS_CODE SAFE_READ_WRITE_FAST SAFE_READ_WRITE_SLOW_PAGE_CROSSED SAFE_READ_WRITE_SLOW_NOT_VALID SAFE_READ_WRITE_SLOW_NOT_USER SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE SAFE_READ_WRITE_SLOW_READ_ONLY SAFE_READ_WRITE_SLOW_HAS_CODE PAGE_FAULT TLB_MISS DO_MANY_CYCLES CYCLE_INTERNAL INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE INVALIDATE_MODULE_DIRTY_PAGE INVALIDATE_PAGE_HAD_CODE INVALIDATE_PAGE_HAD_ENTRY_POINTS DIRTY_PAGE_DID_NOT_HAVE_CODE RUN_FROM_CACHE_EXIT_SAME_PAGE RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE CLEAR_TLB FULL_CLEAR_TLB TLB_FULL TLB_GLOBAL_FULL MODRM_SIMPLE_REG MODRM_SIMPLE_REG_WITH_OFFSET MODRM_SIMPLE_CONST_OFFSET MODRM_COMPLEX SEG_OFFSET_OPTIMISED SEG_OFFSET_NOT_OPTIMISED SEG_OFFSET_NOT_OPTIMISED_ES SEG_OFFSET_NOT_OPTIMISED_FS SEG_OFFSET_NOT_OPTIMISED_GS SEG_OFFSET_NOT_OPTIMISED_NOT_FLAT".split(" "),
d=0;const e={};for(let f=0;f<c.length;f++){const h=c[f];var g=void 0;if(h.includes("/")){d++;const [k,l]=h.split("/");g=e[k]/e[l]}else g=e[h]=a.xa.exports.profiler_stat_get(f-d),g=1E8<=g?Math.round(g/1E6)+"m":1E5<=g?Math.round(g/1E3)+"k":g;b+=h+"="+g+"\n"}b+="\n";c=a.xa.exports.get_valid_tlb_entries_count();d=a.xa.exports.get_valid_global_tlb_entries_count();b=b+("TLB_ENTRIES="+c+" ("+d+" global, "+(c-d)+" non-global)\nWASM_TABLE_FREE=")+(a.xa.exports.jit_get_wasm_table_index_free_list_count()+"\n");
b+="JIT_CACHE_SIZE="+a.xa.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.xa.exports.has_flat_segmentation()+"\n";b+="do_many_cycles avg: "+(a.gk/a.fk||0)+"\n";b+="wasm memory size: "+(a.Ja.buffer.byteLength>>20)+"m\n";b=b+"Config:\nMAX_PAGES="+(a.xa.exports.get_jit_config(0)+"\n");b+="JIT_USE_LOOP_SAFETY="+!!a.xa.exports.get_jit_config(1)+"\n";return b+="MAX_EXTRA_BASIC_BLOCKS="+a.xa.exports.get_jit_config(2)+"\n"},Bj:function(a){return[Ya.oe(a,!1,!1,!1,!1),Ya.oe(a,!0,!1,!1,!1),Ya.oe(a,!1,
!0,!1,!1),Ya.oe(a,!1,!1,!0,!1),Ya.oe(a,!1,!1,!1,!0)].join("\n\n")},oe:function(a,b,c,d,e){let g="";var f=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let n=0;8>n;n++)for(let t of[!1,!0]){var k=a.xa.exports.get_opstats_buffer(b,c,d,e,q,!1,t,n);f.push({Te:q,count:k,ig:t,ag:n});k=a.xa.exports.get_opstats_buffer(b,c,d,e,q,!0,t,n);f.push({Te:3840|q,count:k,ig:t,ag:n})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(let {count:q,Te:n}of f)b.has(n)||
(a+=q);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(let {Te:q,count:n}of f)3840==(q&65280)?b[q&255]+=n:c[q&255]+=n;g=g+"------------------\nTotal: "+(a+"\n");const l=1E7<a?1E3:1;d=Math.max.apply(Math,f.map(({count:q})=>Math.round(q/l)));d=String(d).length;g+=`Instruction counts ${h} (in ${l}):\n`;for(e=0;256>e;e++)g+=e.toString(16).padStart(2,"0")+":"+xb(Math.round(c[e]/l),d),g=15==e%16?g+"\n":g+" ";g=g+"\n"+`Instruction counts ${h} (0f, in ${l}):\n`;for(h=0;256>h;h++)g+=(h&
255).toString(16).padStart(2,"0")+":"+xb(Math.round(b[h]/l),d),g=15==h%16?g+"\n":g+" ";g+="\n";f=f.filter(({count:q})=>q).sort(({count:q},{count:n})=>n-q);for(let {Te:q,ig:n,ag:t,count:m}of f.slice(0,200))g+=q.toString(16)+"_"+t+(n?"_m":"_r")+":"+(m/a*100).toFixed(2)+" ";return g+"\n"}};"undefined"!==typeof module&&"undefined"!==typeof module.exports&&(module.exports.print_stats=Ya);function pf(){this.h=new Map}pf.prototype.read=async function(a,b,c){return(a=this.h.get(a))?a.subarray(b,b+c):null};pf.prototype.cache=async function(a,b){this.h.set(a,b)};pf.prototype.g=function(a){this.h.delete(a)};function qf(a,b){this.h=a;this.Ce=b}function sf(a,b){return new Promise(c=>{Gb(a.Ce+b,{done:async d=>{d=new Uint8Array(d);await a.cache(b,d);c(d)}})})}qf.prototype.read=async function(a,b,c){const d=await this.h.read(a,b,c);return d?d:(await sf(this,a)).subarray(b,b+c)};
qf.prototype.cache=async function(a,b){return await this.h.cache(a,b)};qf.prototype.g=function(a){this.h.g(a)};"undefined"!==typeof window?(window.MemoryFileStorage=pf,window.ServerFileStorageWrapper=qf):"undefined"!==typeof module&&"undefined"!==typeof module.exports?(module.exports.MemoryFileStorage=pf,module.exports.ServerFileStorageWrapper=qf):"function"===typeof importScripts&&(self.MemoryFileStorage=pf,self.ServerFileStorageWrapper=qf);

Binary file not shown.

@ -0,0 +1,229 @@
<!doctype html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Virtual x86</title>
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<meta name="description" content="Run KolibriOS, Linux or Windows 98 in your browser">
<script src="build/v86_all.js"></script>
<link rel="stylesheet" href="v86.css">
<div>
<div id="boot_options">
<h4>Setup</h4>
<table>
<tr>
<td width="350"><label for="cd_image">CD image</label></td>
<td>
<input type="file" id="cd_image" value="images/linux4.iso">
</td>
</tr>
<tr>
<td><label for="floppy_image">Floppy disk image</label></td>
<td> <input type="file" id="floppy_image"><br></td>
</tr>
<tr>
<td><label for="hda_image">Hard drive disk image</label></td>
<td><input type="file" id="hda_image"><br></td>
</tr>
<tr>
<td><label for="multiboot_image">Multiboot kernel image (experimental)</td>
<td><input type="file" id="multiboot_image"><br></td>
</tr>
<tr>
<td><label for="bzimage">Kernel image (bzimage)</label></td>
<td><input type="file" id="bzimage"><br></td>
</tr>
<tr>
<td><label for="initrd">initrd</label></td>
<td><input type="file" id="initrd"><br></td>
</tr>
<tr>
<td colspan="2"><small>Disk images are not uploaded to the server</small><hr></td>
</tr>
<tr>
<td><label for="memory_size">Memory size</label></td>
<td>
<input id="memory_size" type="number" value="1024" min="16" max="2048" step="16"> MB<br>
</td>
</tr>
<tr>
<td><label for="video_memory_size">Video Memory size</label></td>
<td>
<input id="video_memory_size" type="number" value="256" min="128" max="512" step="1"> MB<br>
</td>
</tr>
<tr>
<td><label for="networking_proxy">Networking proxy (leave blank to disable)</label></td>
<td>
<input id="networking_proxy" type="text" value="wss://relay.widgetry.org/">
</td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td><label for="disable_audio">Disable audio</label></td>
<td>
<input id="disable_audio" type="checkbox"><br>
</td>
</tr>
<tr>
<td><label for="enable_acpi">Enable ACPI (experimental)</label></td>
<td>
<input id="enable_acpi" type="checkbox"><br>
</td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<tr>
<td><label for="boot_order">Boot order</label></td>
<td>
<select id="boot_order">
<option value="213">CD / Floppy / Hard Disk</option>
<option value="123">CD / Hard Disk / Floppy</option>
<option value="231">Floppy / CD / Hard Disk</option>
<option value="321">Floppy / Hard Disk / CD</option>
<option value="312">Hard Disk / Floppy / CD</option>
<option value="132">Hard Disk / CD / Floppy</option>
</select>
</td>
</tr>
</table>
<br>
<button id="start_emulation">Start Emulation</button>
</div>
<div id="runtime_options" style="display: none">
<input type="button" value="Pause" id="run">
<input type="button" value="Reset" id="reset">
<input type="button" value="Exit" id="exit">
<input type="button" value="Send Ctrl-Alt-Del" id="ctrlaltdel">
<input type="button" value="Send Alt-Tab" id="alttab">
<input type="button" value="Get floppy image" id="get_fda_image">
<input type="button" value="Get second floppy image" id="get_fdb_image">
<input type="button" value="Get hard disk image" id="get_hda_image">
<input type="button" value="Get second hard disk image" id="get_hdb_image">
<input type="button" value="Get cdrom image" id="get_cdrom_image">
<input type="button" value="Save State" id="save_state">
<input type="button" value="Load State" id="load_state"> <input type="file" style="display: none" id="load_state_input">
<input type="button" value="Memory Dump" id="memory_dump">
<input type="button" value="Capture network traffic" id="capture_network_traffic" title="In wireshark: file -> import from hex -> tick direction indication, timestamp %s.%f">
<input type="button" value="Disable mouse" id="toggle_mouse">
<input type="button" value="Lock mouse" id="lock_mouse">
<input type="button" value="Go fullscreen" id="fullscreen">
<input type="button" value="Take screenshot" id="take_screenshot">
<input type="button" value="Mute" id="mute">
<label>
Scale:
<input type="number" min="0.25" step="0.25" value="1.0" id="scale" style="width: 50px">
</label>
<br>
<label id="change_fda" style="display: none">
Change floppy:
<input type="file">
</label>
<label id="change_cdrom" style="display: none">
Change CD:
<input type="file">
</label>
<br>
</div>
<pre style="display: none" id="loading"></pre>
</div>
<div id="screen_container" style="display: none">
<div id="screen"></div>
<canvas id="vga"></canvas>
<div style="position: absolute; top: 0; z-index: 10">
<textarea class="phone_keyboard"></textarea>
</div>
</div>
<div id="runtime_infos" style="display: none">
Running: <span id="running_time">0s</span> <br>
Speed: <span id="speed">0</span> mIPS<br>
Avg speed: <span id="avg_speed">0</span> mIPS<br>
<br>
<div id="info_storage" style="display: none">
<b>IDE device (HDA or CDROM)</b><br>
Sectors read: <span id="info_storage_sectors_read">0</span><br>
Bytes read: <span id="info_storage_bytes_read">0</span><br>
Sectors written: <span id="info_storage_sectors_written">0</span><br>
Bytes written: <span id="info_storage_bytes_written">0</span><br>
Status: <span id="info_storage_status"></span><br>
<br>
</div>
<div id="info_filesystem" style="display: none">
<b>9p Filesystem</b><br>
Bytes read: <span id="info_filesystem_bytes_read">0</span><br>
Bytes written: <span id="info_filesystem_bytes_written">0</span><br>
<div style="white-space: nowrap; overflow-x: hidden">Last file: <span id="info_filesystem_last_file"></span></div>
Status: <span id="info_filesystem_status"></span><br>
<br>
</div>
<div id="info_network" style="display: none">
<b>Network</b><br>
Bytes received: <span id="info_network_bytes_received">0</span><br>
Bytes transmitted: <span id="info_network_bytes_transmitted">0</span><br>
<br>
</div>
<b>VGA</b><br>
Mode: <span id="info_vga_mode"></span><br>
Resolution: <span id="info_res">-</span><br>
BPP: <span id="info_bpp">-</span><br>
<br>
Mouse: <span id="info_mouse_enabled">No</span><br>
<div id="description" style="display: none"><br></div>
</div>
<div id="filesystem_panel" style="display: none">
<label>
<!--Send files to emulator<br>
<input type="file" id="filesystem_send_file" multiple>-->
Send folder to emulator<br>
<input type="file" id="filesystem_send_file" multiple webkitdirectory>
</label>
<br><br>
<label>
Get file from emulator<br>
<input type="text" id="filesystem_get_file" placeholder="Absolute path">
</label>
</div>
<br style="clear: both"><br>
<div id="terminal"></div>
<br style="clear: both">
<code>Version: <a href="https://github.com/copy/v86/commits/98e7110c2">98e7110c2</a> (Feb 16, 2021 12:02)</code>
<hr>
<a href="debug.html">Enable debug</a>
&mdash;
<a href="https://github.com/copy/v86/blob/master/Readme.md">Readme</a>
&mdash;
<a href="https://github.com/copy/v86">Project on Github</a>
&mdash;
<a href="https://github.com/copy/v86#compatibility">Compatibility</a>

@ -0,0 +1,259 @@
#log, #runtime_infos, #serial, #filesystem_panel, #debug_panel {
font-family: DejaVu Sans Mono, monospace;
font-size: 13px;
border: 1px solid #333;
background-color: #000;
padding: 4px;
color: #fff;
}
#runtime_infos, #filesystem_panel {
float: left;
width: 250px;
margin-bottom: 7px;
margin-right: 7px;
padding-bottom: 7px;
}
#log {
height: 100px;
width: 550px;
}
#debug_panel {
white-space: pre;
float: left;
}
#serial {
margin: 0;
}
#serial:focus {
outline: 1px solid rgb(229, 151, 0);
}
#screen {
white-space: pre;
position: relative;
font-family: Liberation Mono, DejaVu Sans Mono, Courier New, monospace;
font-weight: bold;
font-size: 15px;
line-height: normal;
}
#screen, #vga {
-webkit-transform-origin: top left;
-moz-transform-origin: top left;
transform-origin: top left;
}
#vga {
background-color: #000;
}
body {
background-color: #111;
color: #fff;
line-height: 1.5;
padding: 10px;
font-family: sans-serif;
}
a {
color: wheat;
text-decoration: none;
}
.phone_keyboard {
width: 0;
height: 0;
resize: none;
position: absolute;
opacity: 0;
left: -9999em;
top: 0;
z-index: -10;
white-space: nowrap;
overflow: hidden;
}
h4 {
margin: 0 0 9px 0;
}
#start_emulation {
padding: 6px 18px;
font-size: 16px;
font-weight: bold;
}
#setup_error {
color: red;
font-weight: bold;
background-color: #222;
padding: 8px 18px;
}
#config_link {
font-weight: bold;
background-color: #222;
padding: 8px 18px;
}
#screen_container {
float: left;
margin-right: 10px;
margin-bottom: 10px;
outline: 1px solid #555;
}
#boot_options a {
text-decoration: none;
font-weight: bold;
font-size: 16px;
}
#boot_options td {
padding: 1px 7px;
}
#oses small {
font-size: 80%;
color: #ccc;
padding-left: 5px;
}
#oses tr {
cursor: pointer;
}
#oses {
border-spacing: 0;
}
#oses tr:hover {
background-color: #311;
}
#oses td:nth-child(1) {
white-space: pre;
vertical-align: top;
}
#terminal {
max-width: 1024px;
}
/* the code below was copied from xterm.css */
.xterm {
font-feature-settings: "liga" 0;
position: relative;
user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
.xterm.focus,
.xterm:focus {
outline: none;
}
.xterm .xterm-helpers {
position: absolute;
top: 0;
/**
* The z-index of the helpers must be higher than the canvases in order for
* IMEs to appear on top.
*/
z-index: 5;
}
.xterm .xterm-helper-textarea {
padding: 0;
border: 0;
margin: 0;
/* Move textarea out of the screen to the far left, so that the cursor is not visible */
position: absolute;
opacity: 0;
left: -9999em;
top: 0;
width: 0;
height: 0;
z-index: -5;
/** Prevent wrapping so the IME appears against the textarea at the correct position */
white-space: nowrap;
overflow: hidden;
resize: none;
}
.xterm .composition-view {
/* TODO: Composition position got messed up somewhere */
background: #000;
color: #FFF;
display: none;
position: absolute;
white-space: nowrap;
z-index: 1;
}
.xterm .composition-view.active {
display: block;
}
.xterm .xterm-viewport {
/* On OS X this is required in order for the scroll bar to appear fully opaque */
background-color: #000;
overflow-y: scroll;
cursor: default;
position: absolute;
right: 0;
left: 0;
top: 0;
bottom: 0;
}
.xterm .xterm-screen {
position: relative;
}
.xterm .xterm-screen canvas {
position: absolute;
left: 0;
top: 0;
}
.xterm .xterm-scroll-area {
visibility: hidden;
}
.xterm-char-measure-element {
display: inline-block;
visibility: hidden;
position: absolute;
top: 0;
left: -9999em;
line-height: normal;
}
.xterm {
cursor: text;
}
.xterm.enable-mouse-events {
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
cursor: default;
}
.xterm.xterm-cursor-pointer {
cursor: pointer;
}
.xterm.column-select.focus {
/* Column selection mode */
cursor: crosshair;
}
.xterm .xterm-accessibility,
.xterm .xterm-message {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 10;
color: transparent;
}
.xterm .live-region {
position: absolute;
left: -9999px;
width: 1px;
height: 1px;
overflow: hidden;
}
.xterm-dim {
opacity: 0.5;
}
.xterm-underline {
text-decoration: underline;
}
Loading…
Cancel
Save