Infrastructure in place for 8080 hardware interrupts (more specifically, vertical retrace interrupts)

This commit is contained in:
Jeff Parsons 2016-04-25 18:39:43 -07:00
commit 07259c93ef
17 changed files with 1072 additions and 434 deletions

View file

@ -116,6 +116,7 @@ pcjs:
- /modules/pc8080/lib/cpu.js
- /modules/pc8080/lib/cpusim.js
- /modules/pc8080/lib/cpuops.js
- /modules/pc8080/lib/chipset.js
- /modules/pc8080/lib/rom.js
- /modules/pc8080/lib/ram.js
- /modules/pc8080/lib/keyboard.js

View file

@ -9,7 +9,7 @@
<rom id="romF" addr="0x1000" size="0x0800" file="/devices/pc8080/rom/invaders/INVADERS-F.json"/>
<rom id="romE" addr="0x1800" size="0x0800" file="/devices/pc8080/rom/invaders/INVADERS-E.json"/>
<ram id="ram" addr="0x2000" size="0x2000"/>
<video id="video" screenWidth="224" screenHeight="256" aspect="1.33" rotate="90" addr="0x2400" width="40%" pos="left" padding="8px">
<video id="video" screenWidth="224" screenHeight="256" frameBuffer="0x2400" interruptRate="120" rotation="90" width="40%" pos="left" padding="8px">
<menu>
<title>224x256 Screen (Rotated)</title>
</menu>

View file

@ -1036,10 +1036,41 @@
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="aspectRatio">
<xsl:choose>
<xsl:when test="@aspect"><xsl:value-of select="@aspect"/></xsl:when>
<xsl:when test="@aspectRatio"><xsl:value-of select="@aspectRatio"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="frameBuffer">
<xsl:choose>
<xsl:when test="@frameBuffer"><xsl:value-of select="@frameBuffer"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="interruptRate">
<xsl:choose>
<xsl:when test="@interruptRate"><xsl:value-of select="@interruptRate"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="refreshRate">
<xsl:choose>
<xsl:when test="@refreshRate"><xsl:value-of select="@refreshRate"/></xsl:when>
<xsl:otherwise>60</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rotation">
<xsl:choose>
<xsl:when test="@rotation"><xsl:value-of select="@rotation"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="component">
<xsl:with-param name="machine" select="$machine"/>
<xsl:with-param name="class">video</xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/></xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/>,aspectRatio:<xsl:value-of select="$aspectRatio"/>,frameBuffer:<xsl:value-of select="$frameBuffer"/>,interruptRate:<xsl:value-of select="$interruptRate"/>,refreshRate:<xsl:value-of select="$refreshRate"/>,rotation:<xsl:value-of select="$rotation"/></xsl:with-param>
</xsl:call-template>
</xsl:template>

View file

@ -0,0 +1,486 @@
/**
* @fileoverview Implements the PC8080 ChipSet component.
* @author <a href="mailto:Jeff@pcjs.org">Jeff Parsons</a>
* @version 1.0
* Created 2016-Apr-25
*
* Copyright © 2012-2016 Jeff Parsons <Jeff@pcjs.org>
*
* This file is part of PCjs, which is part of the JavaScript Machines Project (aka JSMachines)
* at <http://jsmachines.net/> and <http://pcjs.org/>.
*
* PCjs is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* PCjs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCjs. If not,
* see <http://www.gnu.org/licenses/gpl.html>.
*
* You are required to include the above copyright notice in every source code file of every
* copy or modified version of this work, and to display that copyright notice on every screen
* that loads or runs any version of this software (see Computer.COPYRIGHT).
*
* Some PCjs files also attempt to load external resource files, such as character-image files,
* ROM files, and disk image files. Those external resource files are not considered part of the
* PCjs program for purposes of the GNU General Public License, and the author does not claim
* any copyright as to their contents.
*/
"use strict";
if (NODE) {
var str = require("../../shared/lib/strlib");
var usr = require("../../shared/lib/usrlib");
var web = require("../../shared/lib/weblib");
var Component = require("../../shared/lib/component");
var Messages = require("./messages");
var State = require("./state");
var CPUDef = require("./cpudef");
}
/**
* ChipSet(parmsChipSet)
*
* The ChipSet component has the following component-specific (parmsChipSet) properties:
*
* model: eg, "SI1978" (should be a member of ChipSet.MODELS)
* swDIP: eg, "00000000", where swDIP[0] is DIP0, swDIP[1] is DIP1, etc.
*
* @constructor
* @extends Component
* @param {Object} parmsChipSet
*/
function ChipSet(parmsChipSet)
{
Component.call(this, "ChipSet", parmsChipSet, ChipSet, Messages.CHIPSET);
var model = parmsChipSet['model'];
/*
* this.model is a numeric version of the 'model' string; when comparing this.model to standard IBM
* model numbers, you should generally compare (this.model|0) to the target value, which truncates it.
*/
if (model && !ChipSet.MODELS[model]) {
Component.notice("Unrecognized ChipSet model: " + model);
}
this.model = ChipSet.MODELS[model];
this.bSwitches = this.parseDIPSwitches(parmsChipSet['swDIP']);
/*
* Here, I'm finally getting around to trying the Web Audio API. Fortunately, based on what little I know about
* sound generation, using the API to make the same noises as the IBM PC speaker seems straightforward.
*
* To start, we create an audio context, unless the 'sound' parameter has been explicitly set to false.
*
* From:
*
* http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/PlayingandSynthesizingSounds/PlayingandSynthesizingSounds.html
*
* "Similar to how HTML5 canvas requires a context on which lines and curves are drawn, Web Audio requires an audio context
* on which sounds are played and manipulated. This context will be the parent object of further audio objects to come....
* Your audio context is typically created when your page initializes and should be long-lived. You can play multiple sounds
* coming from multiple sources within the same context, so it is unnecessary to create more than one audio context per page."
*/
this.fSpeaker = false;
if (parmsChipSet['sound']) {
this.classAudio = this.contextAudio = null;
if (window) {
this.classAudio = window['AudioContext'] || window['webkitAudioContext'];
}
if (this.classAudio) {
this.contextAudio = new this.classAudio();
} else {
if (DEBUG) this.log("AudioContext not available");
}
}
this.setReady();
}
Component.subclass(ChipSet);
ChipSet.SI_1978 = {
MODEL: 1978.1,
STATUS0: {
PORT: 0,
DIP4: 0x01, // self-test request at power up?
ALWAYS_SET: 0x0E, // always set
FIRE: 0x10, // fire
LEFT: 0x20, // move left
RIGHT: 0x40, // move right
PORT7: 0x80 // some connection to port 7?
},
STATUS1: {
PORT: 1,
CREDIT: 0x01, // credit
P1: 0x02, // 1P start
P2: 0x04, // 2P start
ALWAYS_SET: 0x08, // always set
P1_FIRE: 0x10, // P1 fire (cocktail machines only?)
P1_LEFT: 0x20, // P1 left (cocktail machines only?)
P1_RIGHT: 0x40 // P1 right (cocktail machines only?)
},
STATUS2: {
PORT: 2,
DIP3_5: 0x03, // 00 = 3 ships, 01 = 4 ships, 10 = 5 ships, 11 = 6 ships
TILT: 0x04,
DIP6: 0x08, // 0 = extra ship at 1500, 1 = extra ship at 1000
P2_FIRE: 0x10, // P2 fire (cocktail machines only?)
P2_LEFT: 0x20, // P2 left (cocktail machines only?)
P2_RIGHT: 0x40, // P2 right (cocktail machines only?)
DIP7: 0x80 // 0 = display coin info on demo ("attract") screen
},
SHIFT_RESULT: { // bits 0-7 of barrel shifter result
PORT: 3
},
SHIFT_COUNT: {
PORT: 2,
MASK: 0x07
},
SOUND1: {
PORT: 3,
UFO: 0x01,
SHOT: 0x02,
PDEATH: 0x04,
IDEATH: 0x08,
EXPLAY: 0x10,
AMP_ENABLE: 0x20
},
SHIFT_DATA: {
PORT: 4
},
SOUND2: {
PORT: 5,
FLEET1: 0x01,
FLEET2: 0x02,
FLEET3: 0x04,
FLEET4: 0x08,
UFO_HIT: 0x10
}
};
/*
* Supported model strings
*/
ChipSet.MODELS = {
"SI1978": ChipSet.SI_1978.MODEL
};
/**
* parseDIPSwitches(sBits, bDefault)
*
* @this {ChipSet}
* @param {string} sBits describing switch settings
* @param {number} [bDefault]
* @return {number|undefined}
*/
ChipSet.prototype.parseDIPSwitches = function(sBits, bDefault)
{
var b = bDefault;
if (sBits) {
/*
* NOTE: We can't use parseInt() with a base of 2, because both bit order and bit sense are reversed.
*/
b = 0;
var bit = 0x1;
for (var i = 0; i < sBits.length; i++) {
if (sBits.charAt(i) == "0") b |= bit;
bit <<= 1;
}
}
return b;
};
/**
* setBinding(sHTMLType, sBinding, control, sValue)
*
* @this {ChipSet}
* @param {string|null} sHTMLType is the type of the HTML control (eg, "button", "list", "text", "submit", "textarea", "canvas")
* @param {string} sBinding is the value of the 'binding' parameter stored in the HTML control's "data-value" attribute (eg, "sw1")
* @param {Object} control is the HTML control DOM object (eg, HTMLButtonElement)
* @param {string} [sValue] optional data value
* @return {boolean} true if binding was successful, false if unrecognized binding request
*/
ChipSet.prototype.setBinding = function(sHTMLType, sBinding, control, sValue)
{
return false;
};
/**
* initBus(cmp, bus, cpu, dbg)
*
* @this {ChipSet}
* @param {Computer} cmp
* @param {Bus} bus
* @param {CPUSim} cpu
* @param {Debugger} dbg
*/
ChipSet.prototype.initBus = function(cmp, bus, cpu, dbg)
{
this.bus = bus;
this.cpu = cpu;
this.dbg = dbg;
this.cmp = cmp;
if (this.model == ChipSet.SI_1978.MODEL) {
bus.addPortInputTable(this, ChipSet.aPortInput);
bus.addPortOutputTable(this, ChipSet.aPortOutput);
}
};
/**
* powerUp(data, fRepower)
*
* @this {ChipSet}
* @param {Object|null} data
* @param {boolean} [fRepower]
* @return {boolean} true if successful, false if failure
*/
ChipSet.prototype.powerUp = function(data, fRepower)
{
if (!fRepower) {
if (!data) {
this.reset();
} else {
if (!this.restore(data)) return false;
}
}
return true;
};
/**
* powerDown(fSave, fShutdown)
*
* @this {ChipSet}
* @param {boolean} [fSave]
* @param {boolean} [fShutdown]
* @return {Object|boolean} component state if fSave; otherwise, true if successful, false if failure
*/
ChipSet.prototype.powerDown = function(fSave, fShutdown)
{
return fSave? this.save() : true;
};
/**
* reset()
*
* @this {ChipSet}
*/
ChipSet.prototype.reset = function()
{
this.bStatus0 = 0;
this.bStatus1 = 0;
this.bStatus2 = 0;
this.bShiftData = 0;
this.bShiftCount = 0;
this.bSound1 = this.bSound2 = 0;
};
/**
* save()
*
* This implements save support for the ChipSet component.
*
* @this {ChipSet}
* @return {Object}
*/
ChipSet.prototype.save = function()
{
var state = new State(this);
if (this.model == ChipSet.SI_1978.MODEL) {
state.set(0, [this.bStatus0, this.bStatus1, this.bStatus2, this.bShiftData, this.bShiftCount, this.bSound1, this.bSound2]);
}
return state.data();
};
/**
* restore(data)
*
* This implements restore support for the ChipSet component.
*
* @this {ChipSet}
* @param {Object} data
* @return {boolean} true if successful, false if failure
*/
ChipSet.prototype.restore = function(data)
{
var a, i;
a = data[0];
if (this.model == ChipSet.SI_1978.MODEL) {
this.bStatus0 = a[0];
this.bStatus1 = a[1];
this.bStatus2 = a[2];
this.bShiftData = a[3];
this.bShiftCount = a[4];
this.bSound1 = a[5];
this.bSound2 = a[6];
}
return true;
};
/**
* inSIStatus0(port, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x00)
* @param {number} [addrFrom] (not defined if the Debugger is trying to read the specified port)
* @return {number} simulated port value
*/
ChipSet.prototype.inSIStatus0 = function(port, addrFrom)
{
var b = this.bStatus0;
this.printMessageIO(port, null, addrFrom, "STATUS0", b, true);
return b;
};
/**
* inSIStatus1(port, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x01)
* @param {number} [addrFrom] (not defined if the Debugger is trying to read the specified port)
* @return {number} simulated port value
*/
ChipSet.prototype.inSIStatus1 = function(port, addrFrom)
{
var b = this.bStatus1;
this.printMessageIO(port, null, addrFrom, "STATUS1", b, true);
return b;
};
/**
* inSIStatus2(port, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x02)
* @param {number} [addrFrom] (not defined if the Debugger is trying to read the specified port)
* @return {number} simulated port value
*/
ChipSet.prototype.inSIStatus2 = function(port, addrFrom)
{
var b = this.bStatus2;
this.printMessageIO(port, null, addrFrom, "STATUS2", b, true);
return b;
};
/**
* inSIShiftResult(port, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x03)
* @param {number} [addrFrom] (not defined if the Debugger is trying to read the specified port)
* @return {number} simulated port value
*/
ChipSet.prototype.inSIShiftResult = function(port, addrFrom)
{
var b = ((this.bShiftData << this.bShiftCount) >> 8) & 0xff;
this.printMessageIO(port, null, addrFrom, "SHIFT.RESULT", b, true);
return b;
};
/**
* outSIShiftCount(port, b, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x02)
* @param {number} b
* @param {number} [addrFrom] (not defined if the Debugger is trying to write the specified port)
*/
ChipSet.prototype.outSIShiftCount = function(port, b, addrFrom)
{
this.printMessageIO(port, b, addrFrom, "SHIFT.COUNT", null, true);
this.bShiftCount = b;
};
/**
* outSISound1(port, b, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x03)
* @param {number} b
* @param {number} [addrFrom] (not defined if the Debugger is trying to write the specified port)
*/
ChipSet.prototype.outSISound1 = function(port, b, addrFrom)
{
this.printMessageIO(port, b, addrFrom, "SOUND1", null, true);
this.bSound1 = b;
};
/**
* outSIShiftData(port, b, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x04)
* @param {number} b
* @param {number} [addrFrom] (not defined if the Debugger is trying to write the specified port)
*/
ChipSet.prototype.outSIShiftData = function(port, b, addrFrom)
{
this.printMessageIO(port, b, addrFrom, "SHIFT.DATA", null, true);
this.bShiftData = b;
};
/**
* outSISound2(port, b, addrFrom)
*
* @this {ChipSet}
* @param {number} port (0x05)
* @param {number} b
* @param {number} [addrFrom] (not defined if the Debugger is trying to write the specified port)
*/
ChipSet.prototype.outSISound2 = function(port, b, addrFrom)
{
this.printMessageIO(port, b, addrFrom, "SOUND2", null, true);
this.bSound2 = b;
};
/*
* Port input notification tables
*/
ChipSet.aPortInput = {
0x00: ChipSet.prototype.inSIStatus0,
0x01: ChipSet.prototype.inSIStatus1,
0x02: ChipSet.prototype.inSIStatus2,
0x03: ChipSet.prototype.inSIShiftResult
};
/*
* Port output notification tables
*/
ChipSet.aPortOutput = {
0x02: ChipSet.prototype.outSIShiftCount,
0x03: ChipSet.prototype.outSISound1,
0x04: ChipSet.prototype.outSIShiftData,
0x05: ChipSet.prototype.outSISound2
};
/**
* ChipSet.init()
*
* This function operates on every HTML element of class "chipset", extracting the
* JSON-encoded parameters for the ChipSet constructor from the element's "data-value"
* attribute, invoking the constructor to create a ChipSet component, and then binding
* any associated HTML controls to the new component.
*/
ChipSet.init = function()
{
var aeChipSet = Component.getElementsByClass(document, PCJSCLASS, "chipset");
for (var iChip = 0; iChip < aeChipSet.length; iChip++) {
var eChipSet = aeChipSet[iChip];
var parmsChipSet = Component.getComponentParms(eChipSet);
var chipset = new ChipSet(parmsChipSet);
Component.bindComponentControls(chipset, eChipSet, PCJSCLASS);
}
};
/*
* Initialize every ChipSet module on the page.
*/
web.onInit(ChipSet.init);
if (NODE) module.exports = ChipSet;

View file

@ -1479,22 +1479,18 @@ Computer.prototype.updateStatus = function(fForce)
};
/**
* updateVideo(fForce)
* updateVideo(n)
*
* Any high-frequency updates should be performed here. Avoid DOM updates, since updateVideo() can be called up to
* 60 times per second (see VIDEO_UPDATES_PER_SECOND).
* Any high-frequency updates should be performed here (avoid updating DOM elements).
*
* @this {Computer}
* @param {boolean} [fForce] (true to force a video update)
* @param {number} n (where 0 <= n < VIDEO_UPDATES_PER_SECOND for a normal update, or -1 for a forced update)
*/
Computer.prototype.updateVideo = function(fForce)
Computer.prototype.updateVideo = function(n)
{
/*
for (var i = 0; i < this.aVideo.length; i++) {
this.aVideo[i].updateScreen(fForce);
this.aVideo[i].updateScreen(n);
}
if (this.panel) this.panel.updateAnimation();
*/
};
/**

View file

@ -82,6 +82,7 @@ function CPU(parmsCPU, nCyclesDefault)
this.aCounts = {};
this.aCounts.nCyclesPerSecond = nCycles;
this.aCounts.nVideoUpdates = 0;
/*
* nCyclesMultiplier replaces the old "speed" variable (0, 1, 2) and eliminates the need for
@ -148,7 +149,7 @@ Component.subclass(CPU);
* this.aCounts.nCyclesNextStatusUpdate <= this.aCounts.nCyclesPerStatusUpdate
*/
CPU.YIELDS_PER_SECOND = 30;
CPU.VIDEO_UPDATES_PER_SECOND = 60; // WARNING: if you change this, beware of side-effects in the Video component
CPU.VIDEO_UPDATES_PER_SECOND = 60;
CPU.STATUS_UPDATES_PER_SECOND = 2;
CPU.BUTTONS = ["power", "reset"];
@ -173,13 +174,14 @@ CPU.prototype.initBus = function(cmp, bus, cpu, dbg)
if (control) this.cmp.setBinding(null, CPU.BUTTONS[i], control);
}
this.fpu = cmp.getMachineComponent("FPU");
/*
* We need to know the refresh rate (and corresponding interrupt rate, if any) of the Video component.
*/
var video = cmp.getMachineComponent("Video");
this.refreshRate = video && video.getRefreshRate() || CPU.VIDEO_UPDATES_PER_SECOND;
/*
* Attach the ChipSet component to the CPU so that it can obtain the IDT vector number
* of pending hardware interrupts in response to the ChipSet's updateINTR() notifications.
*
* We must also call chipset.updateAllTimers() periodically; stepCPU() takes care of that.
* Attach the ChipSet component to the CPU so that it can be notified whenever the CPU stops and starts.
*/
this.chipset = cmp.getMachineComponent("ChipSet");
@ -197,12 +199,11 @@ CPU.prototype.initBus = function(cmp, bus, cpu, dbg)
/**
* reset()
*
* This is a placeholder for reset (overridden by the CPUSim component).
*
* @this {CPU}
*/
CPU.prototype.reset = function()
{
this.aCounts.nVideoUpdates = 0;
};
/**
@ -550,7 +551,7 @@ CPU.prototype.setBurstCycles = function(nCycles)
* costs are being properly assessed, then we need to update nSnapCycles as well.
*
* TODO: If the delta is negative, we could simply ignore the request, but we must first carefully
* consider the impact on the ChipSet timers.
* consider the impact on the ChipSet timers, if any.
*/
// if (DEBUG) this.nSnapCycles -= nDelta;
this.nStepCycles -= nDelta;
@ -606,7 +607,7 @@ CPU.prototype.calcCycles = function(fRecalc)
* Calculate the most cycles we're allowed to execute in a single "burst"
*/
var nMostUpdatesPerSecond = CPU.YIELDS_PER_SECOND;
if (nMostUpdatesPerSecond < CPU.VIDEO_UPDATES_PER_SECOND) nMostUpdatesPerSecond = CPU.VIDEO_UPDATES_PER_SECOND;
if (nMostUpdatesPerSecond < this.refreshRate) nMostUpdatesPerSecond = this.refreshRate;
if (nMostUpdatesPerSecond < CPU.STATUS_UPDATES_PER_SECOND) nMostUpdatesPerSecond = CPU.STATUS_UPDATES_PER_SECOND;
/*
@ -622,7 +623,7 @@ CPU.prototype.calcCycles = function(fRecalc)
this.aCounts.msPerYield = Math.round(1000 / CPU.YIELDS_PER_SECOND);
this.aCounts.nCyclesPerBurst = Math.floor(this.aCounts.nCyclesPerSecond / nMostUpdatesPerSecond * vMultiplier);
this.aCounts.nCyclesPerYield = Math.floor(this.aCounts.nCyclesPerSecond / CPU.YIELDS_PER_SECOND * vMultiplier);
this.aCounts.nCyclesPerVideoUpdate = Math.floor(this.aCounts.nCyclesPerSecond / CPU.VIDEO_UPDATES_PER_SECOND * vMultiplier);
this.aCounts.nCyclesPerVideoUpdate = Math.floor(this.aCounts.nCyclesPerSecond / this.refreshRate * vMultiplier);
this.aCounts.nCyclesPerStatusUpdate = Math.floor(this.aCounts.nCyclesPerSecond / CPU.STATUS_UPDATES_PER_SECOND * vMultiplier);
/*
@ -807,7 +808,6 @@ CPU.prototype.calcSpeed = function(nCycles, msElapsed)
this.aCounts.mhz = Math.round(nCycles / (msElapsed * 10)) / 100;
if (msElapsed >= 86400000) {
this.nTotalCycles = 0;
if (this.chipset) this.chipset.updateAllTimers(true);
this.setSpeed(); // reset all counters once per day so that we never have to worry about overflow
}
}
@ -965,12 +965,6 @@ CPU.prototype.runCPU = function(fUpdateFocus)
do {
var nCyclesPerBurst = (this.flags.fChecksum? 1 : this.aCounts.nCyclesPerBurst);
if (this.chipset) {
this.chipset.updateAllTimers();
nCyclesPerBurst = this.chipset.getTimerCycleLimit(0, nCyclesPerBurst);
nCyclesPerBurst = this.chipset.getRTCCycleLimit(nCyclesPerBurst);
}
/*
* nCyclesPerBurst is how many cycles we WANT to run on each iteration of stepCPU(), but it may run
* significantly less (or slightly more, since we can't execute partial instructions).
@ -1005,7 +999,8 @@ CPU.prototype.runCPU = function(fUpdateFocus)
this.aCounts.nCyclesNextVideoUpdate -= nCycles;
if (this.aCounts.nCyclesNextVideoUpdate <= 0) {
this.aCounts.nCyclesNextVideoUpdate += this.aCounts.nCyclesPerVideoUpdate;
if (this.cmp) this.cmp.updateVideo();
if (this.cmp) this.cmp.updateVideo(this.aCounts.nVideoUpdates++);
if (this.aCounts.nVideoUpdates > this.refreshRate) this.aCounts.nVideoUpdates = 0;
}
this.aCounts.nCyclesNextStatusUpdate -= nCycles;
@ -1117,7 +1112,7 @@ CPU.prototype.stopCPU = function(fComplete)
CPU.prototype.updateCPU = function(fForce)
{
if (this.cmp) {
this.cmp.updateVideo(fForce);
this.cmp.updateVideo(-1);
this.cmp.updateStatus(fForce);
}
};

View file

@ -91,28 +91,22 @@ var CPUDef = {
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
],
/*
* Bit values for opFlags, which are all reset to zero prior to each instruction
*/
OPFLAG: {
NOREAD: 0x0001, // disable memory reads for the remainder of the current instruction
NOWRITE: 0x0002, // disable memory writes for the remainder of the current instruction
NOINTR: 0x0004 // a segreg has been set, or a prefix, or an STI (delay INTR acknowledgement)
},
/*
* Bit values for intFlags
*/
INTFLAG: {
NONE: 0x00,
INTR: 0x01, // h/w interrupt requested
HALT: 0x04 // halt (HLT) requested
INTL: 0x07, // last interrupt level requested
INTR: 0x08, // set if interrupt has been requested
HALT: 0x10 // halt requested; see the HLT opcode
},
/*
* Opcode definitions
*/
OPCODE: {
ACI: 0xCE, // PS.ALL
CALL: 0xCD
CALL: 0xCD,
RST0: 0xC7
// to be continued....
}
};

View file

@ -2747,7 +2747,7 @@ CPUDef.opCP = function()
*/
CPUDef.opPUPSW = function()
{
this.pushWord(this.getPS() | (this.regA << 8));
this.pushWord((this.getPS() & 0xff) | (this.regA << 8));
this.nStepCycles -= 11;
};

View file

@ -226,6 +226,7 @@ CPUSim.prototype.reset = function()
this.resetRegs();
this.resetCycles();
this.clearError(); // clear any fatal error/exception that setError() may have flagged
this.parent.reset.call(this);
};
/**
@ -255,8 +256,6 @@ CPUSim.prototype.resetRegs = function()
* intFlags contains some internal states we use to indicate whether a hardware interrupt (INTFLAG.INTR) or
* Trap software interrupt (INTR.TRAP) has been requested, as well as when we're in a "HLT" state (INTFLAG.HALT)
* that requires us to wait for a hardware interrupt (INTFLAG.INTR) before continuing execution.
*
* intFlags must be cleared only by checkINTR(), whereas opFlags must be cleared prior to every CPU operation.
*/
this.intFlags = CPUDef.INTFLAG.NONE;
};
@ -286,7 +285,7 @@ CPUSim.prototype.save = function()
{
var state = new State(this);
state.set(0, [this.regA, this.regB, this.regC, this.regD, this.regE, this.regH, this.regL, this.getSP(), this.getPC(), this.getPS()]);
state.set(1, [this.opFlags, this.intFlags, this.nTotalCycles, this.getSpeed()]);
state.set(1, [this.intFlags, this.nTotalCycles, this.getSpeed()]);
state.set(2, this.bus.saveMemory());
return state.data();
};
@ -314,9 +313,8 @@ CPUSim.prototype.restore = function(data)
this.setPC(a[8]);
this.setPS(a[9]);
a = data[1];
this.opFlags = a[0];
this.intFlags = a[1];
this.nTotalCycles = a[2];
this.intFlags = a[0];
this.nTotalCycles = a[1];
this.setSpeed(a[3]);
return this.bus.restoreMemory(data[2]);
};
@ -965,39 +963,52 @@ CPUSim.prototype.pushWord = function(w)
/**
* checkINTR()
*
* This must only be called when intFlags (containing the simulated INTFLAG.INTR signal) is known to be set.
* Note that it's perfectly possible that between the time updateINTR(true) was called and we request the
* interrupt vector number below, the interrupt could have been cleared or masked, in which case getIRRVector()
* will return -1 and we'll simply clear INTFLAG.INTR.
*
* @this {CPUSim}
* @return {boolean} true if h/w interrupt (or trap) has just been acknowledged, false if not
* @return {boolean} true if h/w interrupt has just been acknowledged, false if not
*/
CPUSim.prototype.checkINTR = function()
{
if ((this.intFlags & CPUDef.INTFLAG.INTR) && this.getIF()) {
var bRST = CPUDef.OPCODE.RST0 | ((this.intFlags & CPUDef.INTFLAG.INTL) << 3);
this.clearINTR();
this.clearIF();
this.aOps[bRST].call(this);
return true;
}
return false;
};
/**
* updateINTR(fRaise)
*
* This is called by the ChipSet component whenever a h/w interrupt needs to be simulated.
* This is how the PIC component simulates raising the INTFLAG.INTR signal. We will honor the request
* only if we have a reference back to the ChipSet component. The CPU will then "respond" by calling
* checkINTR() and request the corresponding interrupt vector from the ChipSet.
* clearINTR()
*
* @this {CPUSim}
* @param {boolean} fRaise is true to raise INTFLAG.INTR, false to lower
*/
CPUSim.prototype.updateINTR = function(fRaise)
CPUSim.prototype.clearINTR = function()
{
if (this.chipset) {
if (fRaise) {
this.intFlags |= CPUDef.INTFLAG.INTR;
} else {
this.intFlags &= ~CPUDef.INTFLAG.INTR;
}
}
this.intFlags &= ~(CPUDef.INTFLAG.INTL | CPUDef.INTFLAG.INTR);
};
/**
* requestINTR(nLevel)
*
* This is called by any component that wants to request a h/w interrupt.
*
* NOTE: We allow INTR to be set regardless of the current state of interrupt flag (IF), on the theory
* that if/when the CPU briefly turns interrupts off, it shouldn't lose the last h/w interrupt requested.
* So instead of ignoring INTR here, checkINTR() ignores INTR as long as the interrupt flag (IF) is clear.
*
* The downside is that, as long as the CPU has interrupts disabled, an active INTR state will slow stepCPU()
* down slightly. We could avoid that by introducing a two-stage interrupt tracking system, where a separate
* variable keeps track of the last interrupt requested whenever the interrupt flag (IF) is clear, and when
* setIF() finally occurs, that interrupt is propagated to intFlags. But for now, we're going to assume that
* scenario is rare.
*
* @this {CPUSim}
* @param {number} nLevel (0-7)
*/
CPUSim.prototype.requestINTR = function(nLevel)
{
this.intFlags = (this.intFlags & ~CPUDef.INTFLAG.INTL) | nLevel | CPUDef.INTFLAG.INTR;
};
/**
@ -1110,27 +1121,6 @@ CPUSim.prototype.stepCPU = function(nMinCycles)
*/
this.nBurstCycles = this.nStepCycles = nMinCycles;
/*
* NOTE: Even though runCPU() calls updateAllTimers(), we need an additional call here if we're being
* called from the Debugger, so that any single-stepping will update the timers as well.
*/
if (this.chipset && !nMinCycles) this.chipset.updateAllTimers();
/*
* Let's also suppress h/w interrupts whenever the Debugger is single-stepping an instruction; I'm loathe
* to allow Debugger interactions to affect the behavior of the virtual machine in ANY way, but I'm making
* this small concession to avoid the occasional and sometimes unexpected Debugger command that ends up
* stepping into a hardware interrupt service routine (ISR).
*
* Note that this is similar to the problem discussed in checkINTR() regarding the priority of external h/w
* interrupts vs. Trap interrupts, but they require different solutions, because our Debugger operates
* independently of the CPU.
*
* One exception I make here is when you've asked the Debugger to display PIC messages, the idea being that
* if you're watching the PIC that closely, then you want to hardware interrupts to occur regardless.
*/
if (!nMinCycles) this.opFlags |= CPUDef.OPFLAG.NOINTR;
do {
if (this.intFlags) {
if (this.checkINTR()) {
@ -1138,12 +1128,11 @@ CPUSim.prototype.stepCPU = function(nMinCycles)
this.assert(DEBUGGER); // nMinCycles of zero should be generated ONLY by the Debugger
if (DEBUGGER) {
this.println("interrupt dispatched");
this.opFlags = 0;
break;
}
}
}
if (this.intFlags & CPUDef.INTFLAG.HALT) {
else if (this.intFlags & CPUDef.INTFLAG.HALT) {
/*
* As discussed in opHLT(), the CPU is never REALLY halted by a HLT instruction; instead,
* opHLT() sets CPUDef.INTFLAG.HALT, signalling to us that we're free to end the current burst
@ -1160,7 +1149,6 @@ CPUSim.prototype.stepCPU = function(nMinCycles)
* number of cycles during which we did not actually execute any instructions).
*/
this.nStepCycles = 0;
this.opFlags = 0;
break;
}
}
@ -1173,8 +1161,6 @@ CPUSim.prototype.stepCPU = function(nMinCycles)
nDebugState = 1;
}
this.opFlags = 0;
this.aOps[this.getPCByte()].call(this);
} while (this.nStepCycles > 0);

View file

@ -359,7 +359,7 @@ if (DEBUGGER) {
Debugger.TYPE_E = (Debugger.REG_E << 8 | Debugger.TYPE_REG | Debugger.TYPE_BYTE);
Debugger.TYPE_H = (Debugger.REG_H << 8 | Debugger.TYPE_REG | Debugger.TYPE_BYTE);
Debugger.TYPE_L = (Debugger.REG_L << 8 | Debugger.TYPE_REG | Debugger.TYPE_BYTE);
Debugger.TYPE_M = (Debugger.REG_M << 8 | Debugger.TYPE_REG | Debugger.TYPE_BYTE);
Debugger.TYPE_M = (Debugger.REG_M << 8 | Debugger.TYPE_REG | Debugger.TYPE_BYTE | Debugger.TYPE_MEM);
Debugger.TYPE_BC = (Debugger.REG_BC << 8 | Debugger.TYPE_REG | Debugger.TYPE_WORD);
Debugger.TYPE_DE = (Debugger.REG_DE << 8 | Debugger.TYPE_REG | Debugger.TYPE_WORD);
Debugger.TYPE_HL = (Debugger.REG_HL << 8 | Debugger.TYPE_REG | Debugger.TYPE_WORD);
@ -404,7 +404,7 @@ if (DEBUGGER) {
/* 0x06 */ [Debugger.INS.MVI, Debugger.TYPE_B, Debugger.TYPE_IMM],
/* 0x07 */ [Debugger.INS.RLC],
/* 0x08 */ [Debugger.INS.NOP, Debugger.TYPE_UNDOC],
/* 0x09 */ [Debugger.INS.DAD, Debugger.TYPE_BC | Debugger.TYPE_IN], // REG_HL is the implied (unlisted) destination
/* 0x09 */ [Debugger.INS.DAD, Debugger.TYPE_HL, Debugger.TYPE_BC | Debugger.TYPE_IN], // let's be more explicit about the operands
/* 0x0A */ [Debugger.INS.LDAX, Debugger.TYPE_BC | Debugger.TYPE_MEM],
/* 0x0B */ [Debugger.INS.DCX, Debugger.TYPE_BC],
/* 0x0C */ [Debugger.INS.INR, Debugger.TYPE_C],
@ -420,7 +420,7 @@ if (DEBUGGER) {
/* 0x16 */ [Debugger.INS.MVI, Debugger.TYPE_D, Debugger.TYPE_IMM],
/* 0x17 */ [Debugger.INS.RAL],
/* 0x18 */ [Debugger.INS.NOP, Debugger.TYPE_UNDOC],
/* 0x19 */ [Debugger.INS.DAD, Debugger.TYPE_DE | Debugger.TYPE_IN], // REG_HL is the implied (unlisted) destination
/* 0x19 */ [Debugger.INS.DAD, Debugger.TYPE_HL, Debugger.TYPE_DE | Debugger.TYPE_IN], // let's be more explicit about the operands
/* 0x1A */ [Debugger.INS.LDAX, Debugger.TYPE_DE | Debugger.TYPE_MEM],
/* 0x1B */ [Debugger.INS.DCX, Debugger.TYPE_DE],
/* 0x1C */ [Debugger.INS.INR, Debugger.TYPE_E],
@ -436,7 +436,7 @@ if (DEBUGGER) {
/* 0x26 */ [Debugger.INS.MVI, Debugger.TYPE_H, Debugger.TYPE_IMM],
/* 0x27 */ [Debugger.INS.DAA],
/* 0x28 */ [Debugger.INS.NOP, Debugger.TYPE_UNDOC],
/* 0x29 */ [Debugger.INS.DAD, Debugger.TYPE_HL | Debugger.TYPE_IN], // REG_HL is the implied (unlisted) destination
/* 0x29 */ [Debugger.INS.DAD, Debugger.TYPE_HL, Debugger.TYPE_HL | Debugger.TYPE_IN], // let's be more explicit about the operands
/* 0x2A */ [Debugger.INS.LHLD, Debugger.TYPE_IMM | Debugger.TYPE_WORD | Debugger.TYPE_MEM],
/* 0x2B */ [Debugger.INS.DCX, Debugger.TYPE_HL],
/* 0x2C */ [Debugger.INS.INR, Debugger.TYPE_L],
@ -445,15 +445,15 @@ if (DEBUGGER) {
/* 0x2F */ [Debugger.INS.CMA],
/* 0x30 */ [Debugger.INS.NOP, Debugger.TYPE_UNDOC],
/* 0x31 */ [Debugger.INS.LXI, Debugger.TYPE_SP, Debugger.TYPE_IMM],
/* 0x32 */ [Debugger.INS.STA, Debugger.TYPE_IMM | Debugger.TYPE_BYTE | Debugger.TYPE_MEM],
/* 0x32 */ [Debugger.INS.STA, Debugger.TYPE_IMM | Debugger.TYPE_WORD | Debugger.TYPE_MEM],
/* 0x33 */ [Debugger.INS.INX, Debugger.TYPE_SP],
/* 0x34 */ [Debugger.INS.INR, Debugger.TYPE_M],
/* 0x35 */ [Debugger.INS.DCR, Debugger.TYPE_M],
/* 0x36 */ [Debugger.INS.MVI, Debugger.TYPE_M, Debugger.TYPE_IMM],
/* 0x37 */ [Debugger.INS.STC],
/* 0x38 */ [Debugger.INS.NOP, Debugger.TYPE_UNDOC],
/* 0x39 */ [Debugger.INS.DAD, Debugger.TYPE_SP | Debugger.TYPE_IN], // REG_HL is the implied (unlisted) destination
/* 0x3A */ [Debugger.INS.LDA, Debugger.TYPE_IMM | Debugger.TYPE_BYTE | Debugger.TYPE_MEM],
/* 0x39 */ [Debugger.INS.DAD, Debugger.TYPE_HL, Debugger.TYPE_SP | Debugger.TYPE_IN], // let's be more explicit about the operands
/* 0x3A */ [Debugger.INS.LDA, Debugger.TYPE_IMM | Debugger.TYPE_WORD | Debugger.TYPE_MEM],
/* 0x3B */ [Debugger.INS.DCX, Debugger.TYPE_SP],
/* 0x3C */ [Debugger.INS.INR, Debugger.TYPE_A],
/* 0x3D */ [Debugger.INS.DCR, Debugger.TYPE_A],
@ -622,15 +622,15 @@ if (DEBUGGER) {
/* 0xE0 */ [Debugger.INS.RPO],
/* 0xE1 */ [Debugger.INS.POP, Debugger.TYPE_HL],
/* 0xE2 */ [Debugger.INS.JPO, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
/* 0xE3 */ [Debugger.INS.XTHL],
/* 0xE3 */ [Debugger.INS.XTHL, Debugger.TYPE_SP | Debugger.TYPE_MEM, Debugger.TYPE_HL], // let's be more explicit about the operands
/* 0xE4 */ [Debugger.INS.CPO, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
/* 0xE5 */ [Debugger.INS.PUSH, Debugger.TYPE_HL],
/* 0xE6 */ [Debugger.INS.ANI, Debugger.TYPE_IMM | Debugger.TYPE_BYTE],
/* 0xE7 */ [Debugger.INS.RST],
/* 0xE8 */ [Debugger.INS.RPE],
/* 0xE9 */ [Debugger.INS.PCHL],
/* 0xE9 */ [Debugger.INS.PCHL, Debugger.TYPE_PC, Debugger.TYPE_HL], // let's be more explicit about the operands
/* 0xEA */ [Debugger.INS.JPE, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
/* 0xEB */ [Debugger.INS.XCHG],
/* 0xEB */ [Debugger.INS.XCHG, Debugger.TYPE_HL, Debugger.TYPE_DE], // let's be more explicit about the operands
/* 0xEC */ [Debugger.INS.CPE, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
/* 0xED */ [Debugger.INS.CALL, Debugger.TYPE_IMM | Debugger.TYPE_WORD | Debugger.TYPE_UNDOC],
/* 0xEE */ [Debugger.INS.XRI, Debugger.TYPE_IMM | Debugger.TYPE_BYTE],
@ -644,7 +644,7 @@ if (DEBUGGER) {
/* 0xF6 */ [Debugger.INS.ORI, Debugger.TYPE_IMM | Debugger.TYPE_BYTE],
/* 0xF7 */ [Debugger.INS.RST],
/* 0xF8 */ [Debugger.INS.RM],
/* 0xF9 */ [Debugger.INS.SPHL],
/* 0xF9 */ [Debugger.INS.SPHL, Debugger.TYPE_SP, Debugger.TYPE_HL], // let's be more explicit about the operands
/* 0xFA */ [Debugger.INS.JM, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
/* 0xFB */ [Debugger.INS.EI],
/* 0xFC */ [Debugger.INS.CM, Debugger.TYPE_IMM | Debugger.TYPE_WORD],
@ -672,7 +672,7 @@ if (DEBUGGER) {
"bus": Messages.BUS,
"mem": Messages.MEM,
"port": Messages.PORT,
"timer": Messages.TIMER,
"chipset": Messages.CHIPSET,
"keyboard": Messages.KEYBOARD, // "kbd" is also allowed as shorthand for "keyboard"; see doMessages()
"key": Messages.KEYS, // using "key" instead of "keys", since the latter is a method on JavasScript objects
"video": Messages.VIDEO,
@ -1384,6 +1384,7 @@ if (DEBUGGER) {
case Debugger.REG_E:
case Debugger.REG_H:
case Debugger.REG_L:
case Debugger.REG_M:
case Debugger.REG_F:
cch = 2;
break;
@ -1417,7 +1418,7 @@ if (DEBUGGER) {
n = cpu.regA;
break;
case Debugger.REG_F:
n = cpu.getPS() & 0xff;
n = cpu.getPS();
break;
case Debugger.REG_B:
n = cpu.regB;
@ -1426,7 +1427,7 @@ if (DEBUGGER) {
n = cpu.regC;
break;
case Debugger.REG_BC:
n = (cpu.regB << 8) | cpu.regC;
n = cpu.getBC();
break;
case Debugger.REG_D:
n = cpu.regD;
@ -1435,7 +1436,7 @@ if (DEBUGGER) {
n = cpu.regE;
break;
case Debugger.REG_DE:
n = (cpu.regD << 8) | cpu.regE;
n = cpu.getDE();
break;
case Debugger.REG_H:
n = cpu.regH;
@ -1444,7 +1445,10 @@ if (DEBUGGER) {
n = cpu.regL;
break;
case Debugger.REG_HL:
n = (cpu.regH << 8) | cpu.regL;
n = cpu.getHL();
break;
case Debugger.REG_M:
n = cpu.getByte(cpu.getHL());
break;
case Debugger.REG_PS:
n = (cpu.regA << 8) | (cpu.getPS() & 0xff);
@ -2430,31 +2434,38 @@ if (DEBUGGER) {
var iIns = aOpDesc[0];
var sOperands = "";
var typeSizeDefault = null;
var sOpcode = asOpcodes[iIns];
var cOperands = aOpDesc.length - 1;
var typeSizeDefault = Debugger.TYPE_NONE, type;
for (var iOperand = 1; iOperand <= cOperands; iOperand++) {
var disp, off, cch;
var sOperand = "";
var type = aOpDesc[iOperand];
type = aOpDesc[iOperand];
if (type === undefined) continue;
var typeSize = type & Debugger.TYPE_SIZE;
if (typeSize == Debugger.TYPE_NONE) {
if (typeSizeDefault == null) continue;
typeSize = typeSizeDefault;
if (!typeSize) {
type |= typeSizeDefault;
} else {
typeSizeDefault = typeSize;
}
var typeOther = type & Debugger.TYPE_OTHER;
if (!typeOther) {
type |= (iOperand == 1? Debugger.TYPE_OUT : Debugger.TYPE_IN);
}
typeSizeDefault = typeSize;
var typeMode = type & Debugger.TYPE_MODE;
if (typeMode == Debugger.TYPE_IMM) {
if (typeMode & Debugger.TYPE_IMM) {
sOperand = this.getImmOperand(type, dbgAddr);
}
else if (typeMode == Debugger.TYPE_REG) {
else if (typeMode & Debugger.TYPE_REG) {
sOperand = this.getRegOperand((type & Debugger.TYPE_IREG) >> 8, type, dbgAddr);
}
if (!sOperand || !sOperand.length) {
sOperands = "INVALID";
break;
@ -2472,7 +2483,8 @@ if (DEBUGGER) {
} while (dbgAddrIns.addr != dbgAddr.addr);
}
sLine += str.pad(sBytes, 11);
sLine += str.pad(sBytes, 10);
sLine += (type & Debugger.TYPE_UNDOC)? '*' : ' ';
sLine += str.pad(sOpcode, 7);
if (sOperands) sLine += ' ' + sOperands;
@ -2503,14 +2515,7 @@ if (DEBUGGER) {
switch (typeSize) {
case Debugger.TYPE_BYTE:
/*
* There's the occasional immediate byte we don't need to display (eg, the 0x0A
* following an AAM or AAD instruction), so we suppress the byte if it lacks a TYPE_IN
* or TYPE_OUT designation (and TYPE_BOTH, as the name implies, includes both).
*/
if (type & Debugger.TYPE_BOTH) {
sOperand = str.toHex(this.getByte(dbgAddr, 1), 2);
}
sOperand = str.toHex(this.getByte(dbgAddr, 1), 2);
break;
case Debugger.TYPE_SBYTE:
sOperand = str.toHex((this.getByte(dbgAddr, 1) << 24) >> 24, 4);
@ -2522,6 +2527,9 @@ if (DEBUGGER) {
sOperand = "imm(" + str.toHexWord(type) + ')';
break;
}
if (type & Debugger.TYPE_MEM) {
sOperand = '[' + sOperand + ']';
}
return sOperand;
};
@ -2536,9 +2544,12 @@ if (DEBUGGER) {
*/
Debugger.prototype.getRegOperand = function(iReg, type, dbgAddr)
{
var typeMode = type & Debugger.TYPE_MODE;
var typeSize = type & Debugger.TYPE_SIZE;
return Debugger.REGS[iReg];
/*
* Although this breaks with assembler conventions, I'm going to experiment with some different
* mnemonics; specifically, "[HL]" instead of "M". This is also more in keeping with how getImmOperand()
* displays memory references (ie, by enclosing them in brackets).
*/
return iReg == Debugger.REG_M? "[HL]" : Debugger.REGS[iReg];
};
/**

View file

@ -37,7 +37,7 @@ var Messages = {
BUS: 0x00000040,
MEM: 0x00000080,
PORT: 0x00000100,
TIMER: 0x00000800,
CHIPSET: 0x00008000,
KEYBOARD: 0x00010000,
KEYS: 0x00020000,
VIDEO: 0x00040000,

View file

@ -49,10 +49,12 @@ if (NODE) {
*
* screenWidth: width of the screen canvas, in pixels
* screenHeight: height of the screen canvas, in pixels
* aspect
* rotate
* addr
* screenColor: background color of the screen canvas (default is black)
* aspectRatio
* frameBuffer
* interruptRate (eg, 120)
* refreshRate (eg, 60)
* rotation (eg, 90)
*
* @constructor
* @extends Component
@ -65,11 +67,72 @@ if (NODE) {
function Video(parmsVideo, canvas, context, textarea, container)
{
Component.call(this, "Video", parmsVideo, Video, Messages.VIDEO);
this.interruptRate = parmsVideo['interruptRate'];
this.refreshRate = parmsVideo['refreshRate'] || 60;
this.setReady();
}
Component.subclass(Video);
/**
* initBus(cmp, bus, cpu, dbg)
*
* @this {Video}
* @param {Computer} cmp
* @param {Bus} bus
* @param {CPUSim} cpu
* @param {Debugger} dbg
*/
Video.prototype.initBus = function(cmp, bus, cpu, dbg)
{
this.cmp = cmp;
this.bus = bus;
this.cpu = cpu;
this.dbg = dbg;
};
/**
* getRefreshRate()
*
* @this {Video}
* @return {number}
*/
Video.prototype.getRefreshRate = function()
{
return Math.max(this.refreshRate, this.interruptRate);
};
/**
* updateScreen(n)
*
* Propagates the video buffer to the cell cache and updates the screen with any changes. Forced updates
* are generally internal updates triggered by an I/O operation or other state change, while non-forced updates
* are the periodic updates coming from the CPU.
*
* For every cell in the video buffer, compare it to the cell stored in the cell cache, render if it differs,
* and then update the cell cache to match. Since initCache() sets every cell in the cell cache to an
* invalid value, we're assured that the next call to updateScreen() will redraw the entire (visible) video buffer.
*
* @this {Video}
* @param {number} n (where 0 <= n < getRefreshRate() for a normal update, or -1 for a forced update)
*/
Video.prototype.updateScreen = function(n)
{
if (!(n & 1)) {
/*
* On even updates, call cpu.requestINTR(1), and also update our copy of the screen.
*/
this.cpu.requestINTR(1);
} else {
/*
* On odd updates, call cpu.requestINTR(2), but do NOT update our copy of the screen, because
* the machine has presumably only updated the top half of the frame buffer at this point; it will
* update the bottom half of the frame buffer after acknowledging this interrupt.
*/
this.cpu.requestINTR(2);
}
};
/**
* Video.init()
*

View file

@ -1038,10 +1038,41 @@
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="aspectRatio">
<xsl:choose>
<xsl:when test="@aspect"><xsl:value-of select="@aspect"/></xsl:when>
<xsl:when test="@aspectRatio"><xsl:value-of select="@aspectRatio"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="frameBuffer">
<xsl:choose>
<xsl:when test="@frameBuffer"><xsl:value-of select="@frameBuffer"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="interruptRate">
<xsl:choose>
<xsl:when test="@interruptRate"><xsl:value-of select="@interruptRate"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="refreshRate">
<xsl:choose>
<xsl:when test="@refreshRate"><xsl:value-of select="@refreshRate"/></xsl:when>
<xsl:otherwise>60</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rotation">
<xsl:choose>
<xsl:when test="@rotation"><xsl:value-of select="@rotation"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="component">
<xsl:with-param name="machine" select="$machine"/>
<xsl:with-param name="class">video</xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/></xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/>,aspectRatio:<xsl:value-of select="$aspectRatio"/>,frameBuffer:<xsl:value-of select="$frameBuffer"/>,interruptRate:<xsl:value-of select="$interruptRate"/>,refreshRate:<xsl:value-of select="$refreshRate"/>,rotation:<xsl:value-of select="$rotation"/></xsl:with-param>
</xsl:call-template>
</xsl:template>

View file

@ -148,6 +148,7 @@
"./modules/pc8080/lib/cpu.js",
"./modules/pc8080/lib/cpusim.js",
"./modules/pc8080/lib/cpuops.js",
"./modules/pc8080/lib/chipset.js",
"./modules/pc8080/lib/rom.js",
"./modules/pc8080/lib/ram.js",
"./modules/pc8080/lib/keyboard.js",

View file

@ -1036,10 +1036,41 @@
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="aspectRatio">
<xsl:choose>
<xsl:when test="@aspect"><xsl:value-of select="@aspect"/></xsl:when>
<xsl:when test="@aspectRatio"><xsl:value-of select="@aspectRatio"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="frameBuffer">
<xsl:choose>
<xsl:when test="@frameBuffer"><xsl:value-of select="@frameBuffer"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="interruptRate">
<xsl:choose>
<xsl:when test="@interruptRate"><xsl:value-of select="@interruptRate"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="refreshRate">
<xsl:choose>
<xsl:when test="@refreshRate"><xsl:value-of select="@refreshRate"/></xsl:when>
<xsl:otherwise>60</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rotation">
<xsl:choose>
<xsl:when test="@rotation"><xsl:value-of select="@rotation"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="component">
<xsl:with-param name="machine" select="$machine"/>
<xsl:with-param name="class">video</xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/></xsl:with-param>
<xsl:with-param name="parms">,model:'<xsl:value-of select="$model"/>',mode:<xsl:value-of select="$mode"/>,screenWidth:<xsl:value-of select="$screenWidth"/>,screenHeight:<xsl:value-of select="$screenHeight"/>,memory:<xsl:value-of select="$memory"/>,switches:'<xsl:value-of select="$switches"/>',scale:<xsl:value-of select="$scale"/>,charCols:<xsl:value-of select="$charCols"/>,charRows:<xsl:value-of select="$charRows"/>,fontROM:'<xsl:value-of select="$fontROM"/>',screenColor:'<xsl:value-of select="$screenColor"/>',touchScreen:'<xsl:value-of select="$touchScreen"/>',autoLock:<xsl:value-of select="$autoLock"/>,aspectRatio:<xsl:value-of select="$aspectRatio"/>,frameBuffer:<xsl:value-of select="$frameBuffer"/>,interruptRate:<xsl:value-of select="$interruptRate"/>,refreshRate:<xsl:value-of select="$refreshRate"/>,rotation:<xsl:value-of select="$rotation"/></xsl:with-param>
</xsl:call-template>
</xsl:template>

View file

@ -5,186 +5,193 @@ function ia(a,b,c){var d=0,e=a.length,f=0;for(void 0===c&&(c=function(a,b){retur
function la(a,b){var c;if(Array.prototype.indexOf)return a.indexOf(b,c);c=c||0;0>c&&(c+=a.length);0>c&&(c=0);for(var d=a.length;c<d;c++)if(c in a&&a[c]===b)return c;return-1}
function ma(a,b,c,d){var e=0,f=null,h=null;if("object"==typeof resources&&(f=resources[a]))return d&&d(a,f,e),[f,e];if(c&&"function"==typeof resources)return resources(a,function(b,c){d&&d(a,b,c)}),h;var g=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");c&&(g.onreadystatechange=function(){4===g.readyState&&(f=g.responseText,200==g.status||!g.status&&f.length&&"file:"==(window?window.location.protocol:"file:")||(e=g.status||-1),d&&d(a,f,e))});if(b&&"object"==
typeof b){var k="",l;for(l in b)b.hasOwnProperty(l)&&(k&&(k+="&"),k+=l+"="+encodeURIComponent(b[l]));k=k.replace(/%20/g,"+");g.open("POST",a,!!c);g.setRequestHeader("Content-type","application/x-www-form-urlencoded");g.send(k)}else g.open("GET",a,!!c),"bytes"==b&&g.overrideMimeType("text/plain; charset=x-user-defined"),g.send();c||(f=g.responseText,200!=g.status&&(e=g.status||-1),d&&d(a,f,e),h=[f,e]);return h}function na(){return"http://"+(window?window.location.host:"www.pcjs.org")}
function ua(){return window?window.navigator.userAgent:""}function t(a){window&&window.alert(a)}function va(a){var b=!1;window&&(b=window.confirm(a));return b}var wa=null;function xa(){if(null==wa){var a=!1;if(window)try{window.localStorage.setItem("PCjs.localStorage","PCjs.localStorage"),a="PCjs.localStorage"==window.localStorage.getItem("PCjs.localStorage"),window.localStorage.removeItem("PCjs.localStorage")}catch(b){a=!1}wa=a}return wa}
function ya(a){var b;if(window)try{b=window.localStorage.getItem(a)}catch(c){}return b}function za(a,b){try{return window.localStorage.setItem(a,b),!0}catch(c){}return!1}function Aa(a){if(window){var b=ua();return"iOS"==a&&b.match(/(iPod|iPhone|iPad)/)&&b.match(/AppleWebKit/)||"MSIE"==a&&b.match(/(MSIE|Trident)/)||0<=b.indexOf(a)?!0:!1}return!1}function Ca(a,b,c){function d(){--a;0<=a&&(b()||(a=0));0<a?setTimeout(d,0):c()}d()}
function Da(a,b){function c(){b(100===d)&&(e=setTimeout(c,d),d=100)}var d=0,e=null,f=!1;a.onmousedown=function(){f||e||(d=500,c())};a.ontouchstart=function(){e||(d=500,c())};a.onmouseup=a.onmouseout=function(){e&&(clearTimeout(e),e=null)};a.ontouchend=a.ontouchcancel=function(){e&&(clearTimeout(e),e=null);f=!0}}var Ea={init:[],show:[],exit:[]},Fa=!1,Ka=!0;function La(a,b){if(window){var c=window[a];window[a]="function"!==typeof c?b:function(){c&&c();b()}}}function Ma(a){Ea.init.push(a)}
function Na(a){if(Ka)try{for(var b=0;b<a.length;b++)a[b]()}catch(c){t("An unexpected exception occurred:\n\n"+c.message+"\n\nPlease send this information to support@pcjs.org. Thanks.")}}function Oa(a){!Ka&&a?(Ka=!0,Fa&&Pa("init")):Ka=a}function Pa(a){Ea[a]&&Na(Ea[a])}La("onload",function(){Fa=!0;Na(Ea.init)});La("onpageshow",function(){Na(Ea.show)});La(Aa("Opera")||Aa("iOS")?"onunload":"onbeforeunload",function(){Na(Ea.exit)});
function u(a,b,c,d){this.type=a;b||(b={id:"",name:""});this.id=b.id;this.name=b.name;this.xb=b.comment;this.Mb=b;void 0===this.id&&(this.id="");b=this.id.indexOf(".");0<b?(this.Bb=this.id.substr(0,b),this.Ya=this.id.substr(b+1)):this.Ya=this.id;this[a]=c;this.s={La:!1,Ia:!1,pb:!1,da:!1,Ka:!1};this.mb=null;this.s.Ka=!1;this.N={};this.C=null;this.ga=d||0;w.push(this)}var Qa=void 0,Ra={};
if(window){Qa||(Qa=window.location.search.substr(1));for(var Sa,Ta=/\+/g,Ua=/([^&=]+)=?([^&]*)/g;Sa=Ua.exec(Qa);)Ra[decodeURIComponent(Sa[1].replace(Ta," "))]=decodeURIComponent(Sa[2].replace(Ta," "))}function Va(a){function b(){}if(window){if(!a)throw new TypeError;if(Object.create)return Object.create(a);var c=typeof a;if("object"!==c&&"function"!==c)throw new TypeError;}b.prototype=a;return new b}
function x(a,b){b||(b=u);a.prototype=Va(b.prototype);a.prototype.constructor=a;a.prototype.parent=b.prototype}var w=[],Wa={};function $a(a,b,c){Wa[a]&&b&&(Wa[a][b]=c)}function cb(a){var b,c=[];a&&(a=0<(b=a.indexOf("."))?a.substr(0,b+1):"");for(b=0;b<w.length;b++){var d=w[b];a&&d.id.indexOf(a)||c.push(d)}return c}
function db(a,b){var c;if(void 0!==a){var d;b&&(b=0<(d=b.indexOf("."))?b.substr(0,d+1):"");for(d=0;d<w.length;d++)if(c)c==w[d]&&(c=null);else if(!(a!=w[d].type||b&&w[d].id.indexOf(b)))return w[d]}return null}function y(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")")}catch(c){t(c.message+" ("+a+")")}return b}
function eb(a,b){for(var c=z(b.parentNode,"pc8080-control"),d=0;d<c.length;d++)for(var e=c[d].childNodes,f=0;f<e.length;f++){var h=e[f];if(1===h.nodeType){var g=h.getAttribute("class");if(g)for(var k=g.split(" "),l=0;l<k.length;l++)switch(g=k[l],g){case "pc8080-binding":(g=y(h))&&g.binding&&a.la(g.type,g.binding,h,g.value),l=k.length}}}}
function oa(){return window?window.navigator.userAgent:""}function t(a){window&&window.alert(a)}function pa(a){var b=!1;window&&(b=window.confirm(a));return b}var ra=null;function ya(){if(null==ra){var a=!1;if(window)try{window.localStorage.setItem("PCjs.localStorage","PCjs.localStorage"),a="PCjs.localStorage"==window.localStorage.getItem("PCjs.localStorage"),window.localStorage.removeItem("PCjs.localStorage")}catch(b){a=!1}ra=a}return ra}
function za(a){var b;if(window)try{b=window.localStorage.getItem(a)}catch(c){}return b}function Aa(a,b){try{return window.localStorage.setItem(a,b),!0}catch(c){}return!1}function Ba(a){if(window){var b=oa();return"iOS"==a&&b.match(/(iPod|iPhone|iPad)/)&&b.match(/AppleWebKit/)||"MSIE"==a&&b.match(/(MSIE|Trident)/)||0<=b.indexOf(a)?!0:!1}return!1}function Ca(a,b,c){function d(){--a;0<=a&&(b()||(a=0));0<a?setTimeout(d,0):c()}d()}
function Da(a,b){function c(){b(100===d)&&(e=setTimeout(c,d),d=100)}var d=0,e=null,f=!1;a.onmousedown=function(){f||e||(d=500,c())};a.ontouchstart=function(){e||(d=500,c())};a.onmouseup=a.onmouseout=function(){e&&(clearTimeout(e),e=null)};a.ontouchend=a.ontouchcancel=function(){e&&(clearTimeout(e),e=null);f=!0}}var Ea={init:[],show:[],exit:[]},Ga=!1,Ha=!0;function Ia(a,b){if(window){var c=window[a];window[a]="function"!==typeof c?b:function(){c&&c();b()}}}function Ja(a){Ea.init.push(a)}
function Oa(a){if(Ha)try{for(var b=0;b<a.length;b++)a[b]()}catch(c){t("An unexpected exception occurred:\n\n"+c.message+"\n\nPlease send this information to support@pcjs.org. Thanks.")}}function Pa(a){!Ha&&a?(Ha=!0,Ga&&Qa("init")):Ha=a}function Qa(a){Ea[a]&&Oa(Ea[a])}Ia("onload",function(){Ga=!0;Oa(Ea.init)});Ia("onpageshow",function(){Oa(Ea.show)});Ia(Ba("Opera")||Ba("iOS")?"onunload":"onbeforeunload",function(){Oa(Ea.exit)});
function v(a,b,c,d){this.type=a;b||(b={id:"",name:""});this.id=b.id;this.name=b.name;this.Ab=b.comment;this.Ob=b;void 0===this.id&&(this.id="");b=this.id.indexOf(".");0<b?(this.Eb=this.id.substr(0,b),this.$a=this.id.substr(b+1)):this.$a=this.id;this[a]=c;this.u={Oa:!1,La:!1,rb:!1,ga:!1,Na:!1};this.nb=null;this.u.Na=!1;this.R={};this.C=null;this.fa=d||0;w.push(this)}var Ra=void 0,Sa={};
if(window){Ra||(Ra=window.location.search.substr(1));for(var Ta,Ua=/\+/g,Va=/([^&=]+)=?([^&]*)/g;Ta=Va.exec(Ra);)Sa[decodeURIComponent(Ta[1].replace(Ua," "))]=decodeURIComponent(Ta[2].replace(Ua," "))}function Wa(a){function b(){}if(window){if(!a)throw new TypeError;if(Object.create)return Object.create(a);var c=typeof a;if("object"!==c&&"function"!==c)throw new TypeError;}b.prototype=a;return new b}
function x(a,b){b||(b=v);a.prototype=Wa(b.prototype);a.prototype.constructor=a;a.prototype.parent=b.prototype}var w=[],Xa={};function Ya(a,b,c){Xa[a]&&b&&(Xa[a][b]=c)}function Za(a){var b,c=[];a&&(a=0<(b=a.indexOf("."))?a.substr(0,b+1):"");for(b=0;b<w.length;b++){var d=w[b];a&&d.id.indexOf(a)||c.push(d)}return c}
function $a(a,b){var c;if(void 0!==a){var d;b&&(b=0<(d=b.indexOf("."))?b.substr(0,d+1):"");for(d=0;d<w.length;d++)if(c)c==w[d]&&(c=null);else if(!(a!=w[d].type||b&&w[d].id.indexOf(b)))return w[d]}return null}function y(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")")}catch(c){t(c.message+" ("+a+")")}return b}
function db(a,b){for(var c=z(b.parentNode,"pc8080-control"),d=0;d<c.length;d++)for(var e=c[d].childNodes,f=0;f<e.length;f++){var h=e[f];if(1===h.nodeType){var g=h.getAttribute("class");if(g)for(var k=g.split(" "),l=0;l<k.length;l++)switch(g=k[l],g){case "pc8080-binding":(g=y(h))&&g.binding&&a.ma(g.type,g.binding,h,g.value),l=k.length}}}}
function z(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a.getElementsByClassName(b);var d;c=[];a=a.getElementsByTagName("*");var e=new RegExp("(^| )"+b+"( |$)");b=0;for(d=a.length;b<d;b++)e.test(a[b].className)&&c.push(a[b]);return c}
u.prototype={constructor:u,parent:null,toString:function(){return this.name?this.name:this.id||this.type},la:function(a,b,c){switch(b){case "clear":return this.N[b]||(this.N[b]=c,c.onclick=function(a){return function(){a.N.print&&(a.N.print.value="")}}(this)),!0;case "print":return this.N[b]||(this.Ba=this.N[b]=c,c.value="",this.g=function(a){return function(b,c){8192<a.value.length&&(a.value=a.value.substr(a.value.length-4096));a.value+=(void 0!==c?c+": ":"")+(b||"")+"\n";a.scrollTop=a.scrollHeight}}(c),
this.ka=function(a,b,c){this.g(a,"notice",c)}),!0;default:return!1}},log:function(){},g:function(){},status:function(a){this.g(this.Ya+": "+a)},ka:function(a,b){b||t(a)},va:function(){return this.s.da=!0},ua:function(a,b){b&&(this.s.da=!1);return!0}};function fb(a,b){if(a.C){a===a.C?b|=0:b=b||a.ga;var c=a.C.ga&b;return!!b&&c===b||!!(c&a.C.Tb)}return!1}function gb(a,b){if(a.s.pb)return a.s.Ia&&(a.s.Ia=!1),a.s.pb=!1;if(a.s.Ka)return a.g(a.toString()+" error"),!1;a.s.Ia=b;return a.s.Ia}
function hb(a,b){a.s.Ia&&(b?a.s.pb=!0:void 0===b&&a.g(a.toString()+" busy"));return a.s.Ia}function A(a){if(!a.s.Ka&&(a.s.La=!0,a.s.La)){var b=a.mb;a.mb=null;b&&b()}}function ib(a,b){b&&(a.s.La?b():a.mb=b);return a.s.La}function jb(a,b){a.s.Ka=!0;a.ka(b)}
var kb="undefined"!==typeof ArrayBuffer,lb=[1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,
0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1];function mb(a){u.call(this,"Panel",a,mb)}x(mb);m=mb.prototype;m.la=function(a,b,c,d){return this.u&&this.u.la(a,b,c,d)||this.b&&this.b.la(a,b,c,d)||this.A&&this.A.la(a,b,c,d)||this.C&&this.C.la(a,b,c,d)?!0:this.parent.la.call(this,a,b,c,d)};m.Ma=function(a,b,c,d){this.u=a;this.B=b;this.b=c;this.C=d;this.A=nb(a,"Keyboard")};m.va=function(a,b){b||ob();return!0};m.ua=function(){return!0};m.ma=function(){};
function ob(){for(var a=!1,b=z(document,"pc8080","panel"),c=0;c<b.length;c++){var d=b[c],e=y(d),f;a:{f=e.id;if(void 0!==f)for(var h=void 0,h=0;h<w.length;h++)if(w[h].id===f){f=w[h];break a}f=null}f||(a=!0,f=new mb(e));eb(f,d);a&&A(f)}}Ma(ob);
function pb(a,b,c){u.call(this,"Bus",a,pb);this.b=b;this.C=c;this.U=a.buswidth||16;this.W=Math.pow(2,this.U);this.A=this.W-1|0;this.X=20>=this.U?12:24>=this.U?14:15;this.ha=1<<this.X;this.Y=this.ha>>2;this.u=this.ha-1;this.S=this.W/this.ha|0;this.V=this.S-1;this.F=[];this.G=[];this.H=this.M=!1;this.aa=[];this.ea=[];a=new C;qb(a,this.C);this.B=Array(this.S);for(b=0;b<this.S;b++)this.B[b]=a;a=this.b;b=this.B;c=this.X;var d=this.A;a.ja=b;a.X=c;a.ha=1<<a.X;a.G=a.ha-1;a.Y=b.length;a.W=a.Y-1;a.U=d;A(this)}
x(pb);pb.prototype.reset=function(){};pb.prototype.va=function(a,b){b||this.reset();return!0};function rb(a,b,c,d){for(var e=b>>>a.X;0<c&&e<a.B.length;){var f=a.B[e],h=e*a.ha,g=c>a.ha?a.ha:c;if(f&&f.size){if(f.type==d){if(b+c<=f.w)return f.ib+=f.w-b,f.w=b,!0;if(b>=f.w+f.ib){g=f.size-(b-h);g>c&&(g=c);f.ib=b-f.w+g;c-=g;b=h+a.ha;continue}}return sb(1,b,c)}f=a.B[e];b=new C(b,g,a.ha,d);qb(b,a.C,f);a.B[e++]=b;b=h+a.ha;c-=g}return 0>=c?!0:sb(2,b,c)}
function tb(a,b){return a.B[(b&a.A)>>>a.X].gb(b&a.u,b)}function Cb(a,b){if(void 0===b)return a.H=!a.H,a.H;void 0===a.F[b]&&(a.F[b]=[null,!1]);a.F[b][1]=!a.F[b][1];return a.F[b][1]}function Db(a,b){for(var c=1,d=0,e=0;0<c;){var f=a.F[b],h=a.aa[b]||1,g=1==h?255:2==h?65535:-1,k=g;void 0!==f?(f[0]&&(k=f[0](b,void 0),void 0===k?k=g:k&=g),a.C&&a.H!=f[1]&&Eb(a.C,b,k)):a.C&&(Fb(a.C,a,b,null),a.H&&Eb(a.C,b,k));d|=k<<e;e+=h<<3;b+=h;c-=h}return d}
function Gb(a,b){if(void 0===b)return a.M=!a.M,a.M;void 0===a.G[b]&&(a.G[b]=[null,!1]);a.G[b][1]=!a.G[b][1];return a.G[b][1]}function Hb(a,b,c){for(var d=1,e=0;0<d;){var f=a.G[b],h=a.ea[b]||1,g=1==h?255:2==h?65535:-1,g=(c>>>=e)&g;if(void 0!==f){if(f[0])f[0](b,g,void 0);a.C&&a.M!=f[1]&&Ib(a.C,b,g)}else a.C&&(Fb(a.C,a,b,g),a.M&&Ib(a.C,b,g));e+=h<<3;b+=h;d-=h}}function sb(a,b,c){t("Memory block error ("+a+": "+p(b)+","+p(c)+")");return!1}var Jb;
if(kb){var Kb=new ArrayBuffer(2);(new DataView(Kb)).setUint16(0,256,!0);Jb=256===(new Uint16Array(Kb))[0]}else Jb=!1;var Lb=Jb;
function C(a,b,c,d){this.id=Mb+=2;this.b=null;this.w=a;this.ib=b;this.size=c||0;this.type=d||Nb;this.N=d==Ob;qb(this);this.xa=this.Wb=!1;if(c)if(kb)this.G=new ArrayBuffer(c),this.H=new DataView(this.G,0,c),this.B=new Uint8Array(this.G,0,c),this.S=new Uint16Array(this.G,0,c>>1),this.b=new Int32Array(this.G,0,c>>2),Pb(this,Lb?Qb:Rb);else{this.b=Array(c>>2);for(a=0;a<this.b.length;a++)this.b[a]=0;Pb(this,Sb)}else Pb(this)}var Nb=0,Ob=2,Tb=["NONE","RAM","ROM","VIDEO","H/W"],Mb=0;
C.prototype={constructor:C,parent:null,save:function(){var a,b;if(kb)for(a=Array(this.size>>2),b=0;b<a.length;b++)a[b]=this.H.getInt32(b<<2,!0);else a=this.b;return a},restore:function(a){if(a&&this.size==a.length<<2){var b;if(kb)for(b=0;b<a.length;b++)this.H.setInt32(b<<2,a[b],!0);else this.b=a;return this.xa=!0}return!1},Aa:function(a,b){b?0===this.A++&&Ub(this,Vb,!1):0===this.u++&&Wb(this,Vb,!1)},U:function(){this.C&&fb(this.C,129)&&this.C.message("attempt to read invalid block %"+p(this.w),!0);
return 255},F:function(a,b){this.C&&fb(this.C,129)&&this.C.message("attempt to write "+r(b)+" to invalid block %"+p(this.w),!0)},V:function(a,b){return this.Ta(a++,b++)|this.Ta(a,b)<<8},M:function(a,b,c){this.Va(a++,b&255,c++);this.Va(a,b>>8,c)},ea:function(a){return this.b[a>>2]>>>((a&3)<<3)&255},qa:function(a){var b=a>>2;a=(a&3)<<3;var c=this.b[b]>>a;return 24>a?c&65535:c&255|(this.b[b+1]&255)<<8},Ha:function(a,b){var c=a>>2,d=(a&3)<<3;this.b[c]=this.b[c]&~(255<<d)|b<<d;this.xa=!0},kb:function(a,
b){var c=a>>2,d=(a&3)<<3;24>d?this.b[c]=this.b[c]&~(65535<<d)|b<<d:(this.b[c]=this.b[c]&16777215|b<<24,c++,this.b[c]=this.b[c]&-256|b>>8);this.xa=!0},Y:function(a,b){if(this.C&&null!=this.w){var c=this.C;Xb(c,this.w+a,1,c.Y)&&c.ca(!0)}return this.gb(a,b)},na:function(a,b){if(this.C&&null!=this.w){var c=this.C;Xb(c,this.w+a,2,c.Y)&&c.ca(!0)}return this.ub(a,b)},ya:function(a,b,c){if(this.C&&null!=this.w){var d=this.C;Xb(d,this.w+a,1,d.H)&&d.ca(!0)}this.N?this.F(a,b,c):this.Wa(a,b,c)},Ya:function(a,
b,c){if(this.C&&null!=this.w){var d=this.C;Xb(d,this.w+a,2,d.H)&&d.ca(!0)}this.N?this.F(a,b,c):this.vb(a,b,c)},W:function(a){return this.B[a]},aa:function(a){return this.B[a]},ia:function(a){return this.H.getUint16(a,!0)},pa:function(a){return a&1?this.B[a]|this.B[a+1]<<8:this.S[a>>1]},sa:function(a,b){this.B[a]=b;this.xa=!0},za:function(a,b){this.B[a]=b;this.xa=!0},Xa:function(a,b){this.H.setUint16(a,b,!0);this.xa=!0},Za:function(a,b){a&1?(this.B[a]=b,this.B[a+1]=b>>8):this.S[a>>1]=b;this.xa=!0}};
function qb(a,b,c){a.C=b;a.u=a.A=0;c&&((a.u=c.u)&&Wb(a,Vb,!1),(a.A=c.A)&&Ub(a,Vb,!1))}function Yb(a,b){b?0===--a.A&&(a.Va=a.N?a.F:a.Wa,a.Qb=a.N?a.M:a.vb):0===--a.u&&(a.Ta=a.gb,a.Nb=a.ub)}function Ub(a,b,c){c&&a.A||(a.Va=!a.N&&b[2]||a.F,a.Qb=!a.N&&b[3]||a.M);if(c||void 0===c)a.Wa=b[2]||a.F,a.vb=b[3]||a.M}function Wb(a,b,c){c&&a.u||(a.Ta=b[0]||a.U,a.Nb=b[1]||a.V);if(c||void 0===c)a.gb=b[0]||a.U,a.ub=b[1]||a.V}function Pb(a,b){b||(b=hc);Wb(a,b,void 0);Ub(a,b,void 0)}
var hc=[],Sb=[C.prototype.ea,C.prototype.qa,C.prototype.Ha,C.prototype.kb],Vb=[C.prototype.Y,C.prototype.na,C.prototype.ya,C.prototype.Ya];if(kb)var Rb=[C.prototype.W,C.prototype.ia,C.prototype.sa,C.prototype.Xa],Qb=[C.prototype.aa,C.prototype.pa,C.prototype.za,C.prototype.Za];
function ic(a,b){u.call(this,"CPU",a,ic,1);var c=a.cycles||b,d=a.multiplier||1;this.j={};this.j.Sa=c;this.j.Fa=d;this.j.rb=Math.round(this.j.Sa/1E4)/100;this.j.Da=this.j.rb*this.j.Fa;this.s.fa=!1;this.s.qb=!1;this.s.Fb=a.autoStart;this.s.Gb=!1;this.s.Ja=!1;this.j.$a=this.j.Pa=0;this.j.ab=a.csStart;this.j.Oa=a.csInterval;this.j.Qa=a.csStop;this.ia=this.Ga.bind(this);A(this)}x(ic);var jc=["power","reset"];m=ic.prototype;
m.Ma=function(a,b,c,d){this.u=a;this.B=b;this.C=d;for(b=0;b<jc.length;b++)(c=this.N[jc[b]])&&this.u.la(null,jc[b],c);nb(a,"FPU");this.A=nb(a,"ChipSet");a=kc(a,"autoStart");null!=a&&(this.s.Fb="true"==a?!0:"false"==a?!1:!!a);A(this)};m.reset=function(){};m.save=function(){return null};m.restore=function(){return!1};
m.va=function(a,b){if(!b){if(a&&this.restore){lc(this);if(!this.restore(a))return!1;mc(this)}else this.reset();if(this.C){var c=this.C;c.g("Type ? for help with PC8080 Debugger commands");c.ma();if(c.Za){var d=c.Za;c.Za=null;nc(c,d)}}else this.g("No debugger detected")}D(this);return!0};m.ua=function(a){return a?this.save():!0};function oc(a){(a.s.Fb||!a.C&&void 0===a.N.run)&&a.Ga(!0)}m.Hb=function(){return 0};
function mc(a){void 0===a.j.ab&&(a.j.ab=0);void 0===a.j.Oa&&(a.j.Oa=-1);void 0===a.j.Qa&&(a.j.Qa=-1);a.s.Ja=0<=a.j.ab&&0<a.j.Oa;a.s.Ja&&(a.j.$a=0,a.j.Pa=a.j.ab-a.M)}function pc(a,b){if(a.s.Ja){var c=!1;a.j.$a=a.j.$a+a.Hb()|0;a.j.Pa-=b;0>=a.j.Pa&&(a.j.Pa+=a.j.Oa,c=!0);0<=a.j.Qa&&a.j.Qa<=qc(a)&&(a.j.Oa=a.j.Qa=-1,mc(a),a.ca(),c=!0);c&&a.g(qc(a)+" cycles: checksum="+p(a.j.$a))}}
m.la=function(a,b,c){var d=this;a=!1;switch(b){case "power":case "reset":this.N[b]=c;a=!0;break;case "run":this.N[b]=c;c.onclick=function(){var a;if(a=d.u)if(a=d.u,a.s.da)a=!0;else{var b=null,c,g=cb(a.id);for(c=0;c<g.length&&(b=g[c],b===a||b.s.La);c++);if(c==g.length)for(c=0;c<g.length&&(b=g[c],b===a||b.s.da);c++);c==g.length&&(b=a);t("The "+b.type+" component ("+b.id+") is not "+(b.s.La?"powered yet":"ready yet"+(b.mb?" (waiting for notification)":""))+".");a=!1}a&&(d.s.fa?d.ca(!0):d.Ga(!0))};a=
!0;break;case "speed":this.N[b]=c;a=!0;break;case "setSpeed":this.N[b]=c,c.onclick=function(){rc(d,d.j.Fa<<1,!0)},c.textContent=this.j.Da.toFixed(2)+"Mhz",a=!0}return a};function sc(a,b,c){a.M+=b;c&&(a.F=a.b=0)}
function tc(a,b){var c=30;60>c&&(c=60);2>c&&(c=2);var d=1;b&&1<a.j.Fa&&a.j.Ca&&(d=a.j.Ca/a.j.rb);a.j.Jb=Math.round(1E3/30);a.j.$b=Math.floor(a.j.Sa/c*d);a.j.sb=Math.floor(a.j.Sa/30*d);a.j.Lb=Math.floor(a.j.Sa/60*d);a.j.Kb=Math.floor(a.j.Sa/2*d);b||(a.j.Ra=a.j.sb,a.j.cb=a.j.Lb,a.j.bb=a.j.Kb);a.j.tb=0}function qc(a){return a.M+a.H+a.F-a.b}function lc(a){a.j.Ca=0;a.M=a.H=a.F=a.b=0;mc(a);rc(a,1)}
function rc(a,b,c){var d=!1;if(void 0!==b){.8>a.j.Ca/a.j.Da?b=1:d=!0;a.j.Fa=b;b=a.j.rb*a.j.Fa;if(a.j.Da!=b){a.j.Da=b;b=a.j.Da.toFixed(2)+"Mhz";var e=a.N.setSpeed;e&&(e.textContent=b);a.g("target speed: "+b)}c&&a.u&&a.u.hb()}sc(a,a.H);a.H=0;a.j.Na=ja();a.j.Ea=0;tc(a);return d}
m.Ga=function(a){if(gb(this,!0)){if(!this.s.fa){rc(this);this.u&&this.u.start(this.j.Na,qc(this));this.s.fa=!0;this.s.qb=!0;this.A&&this.A.ac();var b=this.N.run;b&&(b.textContent="Halt");this.u&&(this.u.ma(!0),a&&this.u.hb(!0))}this.j.tb>=this.j.Sa&&tc(this,!0);this.j.eb=0;this.j.nb=ja();this.j.Ea&&(a=this.j.nb-this.j.Ea,a>this.j.Jb&&(this.j.Na+=a,this.j.Na>this.j.nb&&(this.j.Na=this.j.nb)));try{do{var c=this.s.Ja?1:this.j.$b;this.A&&(this.A.Pb(),c=this.A.cc(0,c),c=this.A.bc(c));try{this.Ua(c)}catch(e){if("number"!=
typeof e)throw e;}var d=this.F-this.b;this.H+=d;this.j.eb+=d;sc(this,0,!0);pc(this,d);this.j.cb-=d;0>=this.j.cb&&(this.j.cb+=this.j.Lb);this.j.bb-=d;0>=this.j.bb&&(this.j.bb+=this.j.Kb,this.u&&this.u.ma());this.j.Ra-=d;if(0>=this.j.Ra){this.j.Ra+=this.j.sb;break}}while(this.s.fa)}catch(e){this.ca();D(this);this.u&&this.u.stop(ja(),qc(this));gb(this,!1);jb(this,e.stack||e.message);return}c=setTimeout;d=this.ia;this.j.Ea=ja();a=this.j.Jb;this.j.eb&&(a=Math.round(a*this.j.eb/this.j.sb));a-=this.j.Ea-
this.j.nb;if(b=this.j.Ea-this.j.Na)this.j.Ca=Math.round(this.H/(10*b))/100,864E5<=b&&(this.M=0,this.A&&this.A.Pb(!0),rc(this));if(0>a||this.j.Ca<this.j.Da)a=0;this.j.tb+=this.j.eb;this.j.Ea+=a;c(d,a)}else D(this),this.u&&this.u.stop(ja(),qc(this))};m.Ua=function(){return 0};m.ca=function(a){hb(this,!0);this.F-=this.b;this.b=0;sc(this,this.H);this.H=0;if(this.s.fa){this.s.fa=!1;this.A&&this.A.ac();var b=this.N.run;b&&(b.textContent="Run")}this.s.lb=a};function D(a,b){a.u&&a.u.ma(b)}
function uc(a){this.Ib=a.model||8080;ic.call(this,a,1E6);this.ea=vc;lc(this);this.s.lb=this.s.Vb=!1;this.aa=0;this.ja=[];this.X=this.ha=this.G=this.Y=this.W=this.U=0;wc(this)}x(uc,ic);m=uc.prototype;m.reset=function(){this.s.fa&&this.ca();wc(this);lc(this);this.s.Ka=!1};function wc(a){a.i=0;a.I=0;a.O=0;a.J=0;a.P=0;a.K=0;a.R=0;a.Z=0;E(a,0);xc(a,0);a.S=0}m.Hb=function(){var a=this.i+this.I+this.O+this.J+this.P+this.K+this.R|0;return a=a+this.Z+this.L+yc(this)|0};
m.save=function(){var a=new G(this);I(a,0,[this.i,this.I,this.O,this.J,this.P,this.K,this.R,this.Z,this.L,yc(this)]);I(a,1,[this.V,this.S,this.M,this.j.Fa]);for(var b=this.B,c=0,d=[],e=0;e<b.S;e++){var f=b.B[e];if(f.xa||f.Wb){d[c++]=e;var h=c++;a:if(f=f.save()){for(var g=0,k=0,l=[];g<f.length;){for(var n=f[g],q=g+1;q<f.length&&f[q]===n;)q++;l[k++]=q-g;l[k++]=n;g=q}if(l.length<f.length){f=l;break a}}d[h]=f}}I(a,2,d);return a.data()};
m.restore=function(a){var b=a[0];this.i=b[0];this.I=b[1];this.O=b[2];this.J=b[3];this.P=b[4];this.K=b[5];this.R=b[6];this.Z=b[7]&65535;E(this,b[8]);xc(this,b[9]);b=a[1];this.V=b[0];this.S=b[1];this.M=b[2];rc(this,b[3]);a:{b=this.B;a=a[2];var c;for(c=0;c<a.length-1;c+=2){var d=a[c],e=a[c+1];if(e&&e.length<b.Y){for(var f=0,h=Array(b.Y),g=0;g<e.length-1;)for(var k=e[g++],l=e[g++];k--;)h[f++]=l;e=h}f=b.B[d];if(!f||!f.restore(e)){t("Unable to restore memory block "+d);b=!1;break a}}b=!0}return b};
m.la=function(a,b,c){var d=!1;switch(b){case "A":case "B":case "C":case "D":case "E":case "H":case "L":case "SP":case "PC":case "F":case "SF":case "ZF":case "AF":case "PF":case "CF":this.N[b]=c;this.aa++;d=!0;break;default:d=this.parent.la.call(this,a,b,c)}return d};function zc(a){return a.I<<8|a.O}function Ac(a,b){a.I=b>>8&255;a.O=b&255}function Bc(a){return a.J<<8|a.P}function Cc(a,b){a.J=b>>8&255;a.P=b&255}function J(a){return a.K<<8|a.R}function L(a,b){a.K=b>>8&255;a.R=b&255}
function E(a,b){a.L=b&65535}function M(a){return a.D&256?1:0}function N(a){return lb[a.T&255]?4:0}function Dc(a){return(a.T^a.ba)&16?16:0}function Ec(a){return a.D&255?0:64}function Fc(a){return a.T&128?128:0}function yc(a){return a.oa&-214|Fc(a)|Ec(a)|Dc(a)|N(a)|M(a)}function xc(a,b){a.D=a.T=a.ba=0;b&1&&(a.D|=256);b&4||(a.T|=1);b&16&&(a.ba|=16);b&64||(a.D|=255);b&128&&(a.T^=192);a.oa=a.oa&-513|b&512|2}function Gc(a,b){a.ba=a.i^b;return(a.D=a.T=a.i+b)&255}
function Hc(a,b){a.ba=a.i^b;return(a.D=a.T=a.i+b+(a.D&256?1:0))&255}function Ic(a,b){return a.D=a.T=a.ba=a.i&b}function bd(a,b){a.ba=a.i^b;a.D=a.T=a.i-b}function cd(a,b){a.ba=b;b=(a.T=b-1)&255;a.D=a.D&-256|b;return b}function dd(a,b){a.ba=b;b=(a.T=b+1)&255;a.D=a.D&-256|b;return b}function ed(a,b){return a.D=a.T=a.ba=a.i|b}function fd(a,b){a.ba=a.i^b;return(a.D=a.T=a.i-b)&255}function gd(a,b){a.ba=a.i^b;return(a.D=a.T=a.i-b-(a.D&256?1:0))&255}function hd(a,b){return a.D=a.T=a.ba=a.i^b}
function O(a,b){return a.ja[(b&a.U)>>>a.X].Ta(b&a.G,b)}function id(a,b){var c=b&a.G,d=(b&a.U)>>>a.X;if(c<a.G)return a.ja[d].Nb(c,b);c=a.ja[d].Ta(c,b);return c|=a.ja[d+1&a.W].Ta(0,b+1)<<8}function P(a,b,c){a.ja[(b&a.U)>>>a.X].Va(b&a.G,c&255,b)}function jd(a,b,c){var d=b&a.G,e=(b&a.U)>>>a.X;d<a.G?a.ja[e].Qb(d,c&65535,b):(a.ja[e++].Va(d,c&255,b),a.ja[e&a.W].Va(0,c>>8&255,b+1))}function Q(a){var b=O(a,a.L);E(a,a.L+1);return b}function T(a){var b=id(a,a.L);E(a,a.L+2);return b}
function U(a){var b=id(a,a.Z);a.Z=a.Z+2&65535;return b}function V(a,b){a.Z=a.Z-2&65535;jd(a,a.Z,b)}function W(a,b,c,d){d=d||2;a.N[b]&&(void 0===c&&(jb(a,"Value for "+b+" is invalid"),a.ca()),c=!a.s.fa||a.s.Gb?p(c,d):"--------".substr(0,d),a.N[b].textContent!=c&&(a.N[b].textContent=c))}
m.ma=function(a){this.aa&&(a||!this.s.fa||this.s.Gb)&&(W(this,"A",this.i),W(this,"B",this.I),W(this,"C",this.O),W(this,"D",this.J),W(this,"E",this.P),W(this,"H",this.K),W(this,"L",this.R),W(this,"SP",this.Z,4),W(this,"PC",this.L,4),a=yc(this),W(this,"F",a,2),W(this,"SF",a&128,1),W(this,"ZF",a&64,1),W(this,"AF",a&16,1),W(this,"PF",a&4,1),W(this,"CF",a&1,1));if(a=this.N.speed)a.textContent=this.s.fa&&this.j.Ca?this.j.Ca.toFixed(2)+"Mhz":"Stopped"};
m.Ua=function(a){this.s.lb=!0;var b=this.s.Vb=this.C&&kd(this.C),c=a?this.s.qb?0:1:-1;this.s.qb=!1;this.F=this.b=a;this.A&&!a&&this.A.Pb();a||(this.V|=4);do{if(this.S&&this.S&4){this.V=this.b=0;break}if(b){if(ld(this.C,this.L,c)){this.ca();break}c=1}this.V=0;this.ea[Q(this)].call(this)}while(0<this.b);return this.s.lb?this.F-this.b:void 0===this.s.lb?0:-1};Ma(function(){for(var a=z(document,"pc8080","cpu"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new uc(d);eb(d,c)}});function md(){this.b-=4}
function nd(){E(this,T(this));this.b-=10}function od(){E(this,U(this));this.b-=10}function pd(){var a=T(this);V(this,this.L);E(this,a);this.b-=17}
var vc=[md,function(){Ac(this,T(this));this.b-=10},function(){P(this,zc(this),this.i);this.b-=7},function(){Ac(this,zc(this)+1);this.b-=5},function(){this.I=dd(this,this.I);this.b-=5},function(){this.I=cd(this,this.I);this.b-=5},function(){this.I=Q(this);this.b-=7},function(){var a=this.i<<1;this.i=a&255|a>>8;this.D=this.D&255|a&256;this.b-=4},md,function(){var a;L(this,a=J(this)+zc(this));this.D=this.D&255|a>>8&256;this.b-=10},function(){this.i=O(this,zc(this));this.b-=7},function(){Ac(this,zc(this)-
1);this.b-=5},function(){this.O=dd(this,this.O);this.b-=5},function(){this.O=cd(this,this.O);this.b-=5},function(){this.O=Q(this);this.b-=7},function(){var a=this.i<<8&256;this.i=(a|this.i)>>1;this.D=this.D&255|a;this.b-=4},md,function(){Cc(this,T(this));this.b-=10},function(){P(this,Bc(this),this.i);this.b-=7},function(){Cc(this,Bc(this)+1);this.b-=5},function(){this.J=dd(this,this.J);this.b-=5},function(){this.J=cd(this,this.J);this.b-=5},function(){this.J=Q(this);this.b-=7},function(){var a=this.i<<
1;this.i=a&255|this.D>>8;this.D=this.D&255|a&256;this.b-=4},md,function(){var a;L(this,a=J(this)+Bc(this));this.D=this.D&255|a>>8&256;this.b-=10},function(){this.i=O(this,Bc(this));this.b-=7},function(){Cc(this,Bc(this)-1);this.b-=5},function(){this.P=dd(this,this.P);this.b-=5},function(){this.P=cd(this,this.P);this.b-=5},function(){this.P=Q(this);this.b-=7},function(){var a=this.i<<8&256;this.i=(this.D&256|this.i)>>1;this.D=this.D&255|a;this.b-=4},md,function(){L(this,T(this));this.b-=10},function(){jd(this,
T(this),J(this));this.b-=16},function(){L(this,J(this)+1);this.b-=5},function(){this.K=dd(this,this.K);this.b-=5},function(){this.K=cd(this,this.K);this.b-=5},function(){this.K=Q(this);this.b-=7},function(){var a=this.i,b=!!M(this),c=!!Dc(this);9<(a&15)||c?(a+=6,c=!0):c=!1;160<=a||b?(a+=96,b=!0):b=!1;this.D=this.T=this.i=a&255;this.D=b?this.D|256:this.D&-257;this.ba=c?~this.T&16|this.ba&-17:this.T&16|this.ba&-17;this.b-=4},md,function(){var a;L(this,a=J(this)+J(this));this.D=this.D&255|a>>8&256;this.b-=
10},function(){L(this,id(this,T(this)));this.b-=16},function(){L(this,J(this)-1);this.b-=5},function(){this.R=dd(this,this.R);this.b-=5},function(){this.R=cd(this,this.R);this.b-=5},function(){this.R=Q(this);this.b-=7},function(){this.i=~this.i&255;this.b-=4},md,function(){this.Z=T(this)&65535;this.b-=10},function(){P(this,T(this),this.i);this.b-=13},function(){this.Z=this.Z+1&65535;this.b-=5},function(){var a=J(this);P(this,a,dd(this,O(this,a)));this.b-=10},function(){var a=J(this);P(this,a,cd(this,
O(this,a)));this.b-=10},function(){P(this,J(this),Q(this));this.b-=10},function(){this.D|=256;this.b-=4},md,function(){var a;this.Z=(a=J(this)+this.Z)&65535;this.D=this.D&255|a>>8&256;this.b-=10},function(){this.i=O(this,T(this));this.b-=13},function(){this.Z=this.Z-1&65535;this.b-=5},function(){this.i=dd(this,this.i);this.b-=5},function(){this.i=cd(this,this.i);this.b-=5},function(){this.i=Q(this);this.b-=7},function(){this.D=M(this)?this.D&-257:this.D|256;this.b-=4},function(){this.b-=5},function(){this.I=
this.O;this.b-=5},function(){this.I=this.J;this.b-=5},function(){this.I=this.P;this.b-=5},function(){this.I=this.K;this.b-=5},function(){this.I=this.R;this.b-=5},function(){this.I=O(this,J(this));this.b-=7},function(){this.I=this.i;this.b-=5},function(){this.O=this.I;this.b-=5},function(){this.b-=5},function(){this.O=this.J;this.b-=5},function(){this.O=this.P;this.b-=5},function(){this.O=this.K;this.b-=5},function(){this.O=this.R;this.b-=5},function(){this.O=O(this,J(this));this.b-=7},function(){this.O=
this.i;this.b-=5},function(){this.J=this.I;this.b-=5},function(){this.J=this.O;this.b-=5},function(){this.b-=5},function(){this.J=this.P;this.b-=5},function(){this.J=this.K;this.b-=5},function(){this.J=this.R;this.b-=5},function(){this.J=O(this,J(this));this.b-=7},function(){this.J=this.i;this.b-=5},function(){this.P=this.I;this.b-=5},function(){this.P=this.O;this.b-=5},function(){this.P=this.J;this.b-=5},function(){this.b-=5},function(){this.P=this.K;this.b-=5},function(){this.P=this.R;this.b-=5},
function(){this.P=O(this,J(this));this.b-=7},function(){this.P=this.i;this.b-=5},function(){this.K=this.I;this.b-=5},function(){this.K=this.O;this.b-=5},function(){this.K=this.J;this.b-=5},function(){this.K=this.P;this.b-=5},function(){this.b-=5},function(){this.K=this.R;this.b-=5},function(){this.K=O(this,J(this));this.b-=7},function(){this.K=this.i;this.b-=5},function(){this.R=this.I;this.b-=5},function(){this.R=this.O;this.b-=5},function(){this.R=this.J;this.b-=5},function(){this.R=this.P;this.b-=
5},function(){this.R=this.K;this.b-=5},function(){this.b-=5},function(){this.R=O(this,J(this));this.b-=7},function(){this.R=this.i;this.b-=5},function(){P(this,J(this),this.I);this.b-=7},function(){P(this,J(this),this.O);this.b-=7},function(){P(this,J(this),this.J);this.b-=7},function(){P(this,J(this),this.P);this.b-=7},function(){P(this,J(this),this.K);this.b-=7},function(){P(this,J(this),this.R);this.b-=7},function(){this.S|=4;this.b-=7;this.C&&fb(this,-2147483648)?(E(this,this.L-1),this.C.ca()):
this.oa&512||(this.C&&E(this,this.L-1),this.ca())},function(){P(this,J(this),this.i);this.b-=7},function(){this.i=this.I;this.b-=5},function(){this.i=this.O;this.b-=5},function(){this.i=this.J;this.b-=5},function(){this.i=this.P;this.b-=5},function(){this.i=this.K;this.b-=5},function(){this.i=this.R;this.b-=5},function(){this.i=O(this,J(this));this.b-=7},function(){this.b-=5},function(){this.i=Gc(this,this.I);this.b-=4},function(){this.i=Gc(this,this.O);this.b-=4},function(){this.i=Gc(this,this.J);
this.b-=4},function(){this.i=Gc(this,this.P);this.b-=4},function(){this.i=Gc(this,this.K);this.b-=4},function(){this.i=Gc(this,this.R);this.b-=4},function(){this.i=Gc(this,O(this,J(this)));this.b-=7},function(){this.i=Gc(this,this.i);this.b-=4},function(){this.i=Hc(this,this.I);this.b-=4},function(){this.i=Hc(this,this.O);this.b-=4},function(){this.i=Hc(this,this.J);this.b-=4},function(){this.i=Hc(this,this.P);this.b-=4},function(){this.i=Hc(this,this.K);this.b-=4},function(){this.i=Hc(this,this.R);
this.b-=4},function(){this.i=Hc(this,O(this,J(this)));this.b-=7},function(){this.i=Hc(this,this.i);this.b-=4},function(){this.i=fd(this,this.I);this.b-=4},function(){this.i=fd(this,this.O);this.b-=4},function(){this.i=fd(this,this.J);this.b-=4},function(){this.i=fd(this,this.P);this.b-=4},function(){this.i=fd(this,this.K);this.b-=4},function(){this.i=fd(this,this.R);this.b-=4},function(){this.i=fd(this,O(this,J(this)));this.b-=7},function(){this.i=fd(this,this.i);this.b-=4},function(){this.i=gd(this,
this.I);this.b-=4},function(){this.i=gd(this,this.O);this.b-=4},function(){this.i=gd(this,this.J);this.b-=4},function(){this.i=gd(this,this.P);this.b-=4},function(){this.i=gd(this,this.K);this.b-=4},function(){this.i=gd(this,this.R);this.b-=4},function(){this.i=gd(this,O(this,J(this)));this.b-=7},function(){this.i=gd(this,this.i);this.b-=4},function(){this.i=Ic(this,this.I);this.b-=4},function(){this.i=Ic(this,this.O);this.b-=4},function(){this.i=Ic(this,this.J);this.b-=4},function(){this.i=Ic(this,
this.P);this.b-=4},function(){this.i=Ic(this,this.K);this.b-=4},function(){this.i=Ic(this,this.R);this.b-=4},function(){this.i=Ic(this,O(this,J(this)));this.b-=7},function(){this.i=Ic(this,this.i);this.b-=4},function(){this.i=hd(this,this.I);this.b-=4},function(){this.i=hd(this,this.O);this.b-=4},function(){this.i=hd(this,this.J);this.b-=4},function(){this.i=hd(this,this.P);this.b-=4},function(){this.i=hd(this,this.K);this.b-=4},function(){this.i=hd(this,this.R);this.b-=4},function(){this.i=hd(this,
O(this,J(this)));this.b-=7},function(){this.i=hd(this,this.i);this.b-=4},function(){this.i=ed(this,this.I);this.b-=4},function(){this.i=ed(this,this.O);this.b-=4},function(){this.i=ed(this,this.J);this.b-=4},function(){this.i=ed(this,this.P);this.b-=4},function(){this.i=ed(this,this.K);this.b-=4},function(){this.i=ed(this,this.R);this.b-=4},function(){this.i=ed(this,O(this,J(this)));this.b-=7},function(){this.i=ed(this,this.i);this.b-=4},function(){bd(this,this.I);this.b-=4},function(){bd(this,this.O);
this.b-=4},function(){bd(this,this.J);this.b-=4},function(){bd(this,this.P);this.b-=4},function(){bd(this,this.K);this.b-=4},function(){bd(this,this.R);this.b-=4},function(){bd(this,O(this,J(this)));this.b-=7},function(){bd(this,this.i);this.b-=4},function(){Ec(this)||(E(this,U(this)),this.b-=6);this.b-=5},function(){Ac(this,U(this));this.b-=10},function(){var a=T(this);Ec(this)||E(this,a);this.b-=10},nd,function(){var a=T(this);Ec(this)||(V(this,this.L),E(this,a),this.b-=6);this.b-=11},function(){V(this,
zc(this));this.b-=11},function(){this.i=Gc(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,0);this.b-=11},function(){Ec(this)&&(E(this,U(this)),this.b-=6);this.b-=5},od,function(){var a=T(this);Ec(this)&&E(this,a);this.b-=10},nd,function(){var a=T(this);Ec(this)&&(V(this,this.L),E(this,a),this.b-=6);this.b-=11},pd,function(){this.i=Hc(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,8);this.b-=11},function(){M(this)||(E(this,U(this)),this.b-=6);this.b-=5},function(){Cc(this,U(this));
this.b-=10},function(){var a=T(this);M(this)||E(this,a);this.b-=10},function(){var a=Q(this);Hb(this.B,a,this.i);this.b-=10},function(){var a=T(this);M(this)||(V(this,this.L),E(this,a),this.b-=6);this.b-=11},function(){V(this,Bc(this));this.b-=11},function(){this.i=fd(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,16);this.b-=11},function(){M(this)&&(E(this,U(this)),this.b-=6);this.b-=5},od,function(){var a=T(this);M(this)&&E(this,a);this.b-=10},function(){var a=Q(this);this.i=Db(this.B,
a)&255;this.b-=10},function(){var a=T(this);M(this)&&(V(this,this.L),E(this,a),this.b-=6);this.b-=11},pd,function(){this.i=gd(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,24);this.b-=11},function(){N(this)||(E(this,U(this)),this.b-=6);this.b-=5},function(){L(this,U(this));this.b-=10},function(){var a=T(this);N(this)||E(this,a);this.b-=10},function(){var a=U(this);V(this,J(this));L(this,a);this.b-=18},function(){var a=T(this);N(this)||(V(this,this.L),E(this,a),this.b-=6);this.b-=11},function(){V(this,
J(this));this.b-=11},function(){this.i=Ic(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,32);this.b-=11},function(){N(this)&&(E(this,U(this)),this.b-=6);this.b-=5},function(){E(this,J(this));this.b-=5},function(){var a=T(this);N(this)&&E(this,a);this.b-=10},function(){var a=J(this);L(this,Bc(this));Cc(this,a);this.b-=5},function(){var a=T(this);N(this)&&(V(this,this.L),E(this,a),this.b-=6);this.b-=11},pd,function(){this.i=hd(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,40);
this.b-=11},function(){Fc(this)||(E(this,U(this)),this.b-=6);this.b-=5},function(){var a=U(this);xc(this,a);this.i=a>>8;this.b-=10},function(){var a=T(this);Fc(this)||E(this,a);this.b-=10},function(){this.oa&=-513;this.b-=4},function(){var a=T(this);Fc(this)||(V(this,this.L),E(this,a),this.b-=6);this.b-=11},function(){V(this,yc(this)|this.i<<8);this.b-=11},function(){this.i=ed(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,48);this.b-=11},function(){Fc(this)&&(E(this,U(this)),this.b-=6);
this.b-=5},function(){this.Z=J(this)&65535;this.b-=5},function(){var a=T(this);Fc(this)&&E(this,a);this.b-=10},function(){this.oa|=512;this.b-=4},function(){var a=T(this);Fc(this)&&(V(this,this.L),E(this,a),this.b-=6);this.b-=11},pd,function(){bd(this,Q(this));this.b-=7},function(){V(this,this.L);E(this,56);this.b-=11}];
function qd(a){u.call(this,"ROM",a,qd);this.u=null;this.H=a.addr;this.A=a.size;this.F=a.alias;this.G=a.file;this.M=ba(this.G);if(this.G){a=this.G;var b=ca(this.M);"json"!=b&&"hex"!=b&&(a=na()+"/api/v1/dump?file="+this.G+"&format=bytes&decimal=true");var c=this;ma(a,null,!0,function(a,b,f){rd(c,a,b,f)})}}x(qd);qd.prototype.Ma=function(a,b,c,d){this.B=b;this.b=c;this.C=d;sd(this)};
qd.prototype.va=function(){if(this.ta){if(this.C){var a=this.C,b=this.id,c=this.H,d=this.A,e=this.ta,f=[],h;for(h in e){var g=e[h];"number"==typeof g&&(e[h]=g={o:g});var k=g.o,l=g.a;if(void 0!==k){var n=f,k=[k>>>0,h],q=ia(n,k,a.yb);0>q&&n.splice(-(q+1),0,k)}l&&(g.a=l.replace(/''/g,'"'))}a.M.push({dc:b,w:c,Zb:d,ta:e,zb:f})}delete this.ta}return!0};qd.prototype.ua=function(){return!0};
function rd(a,b,c,d){if(d)a.ka("Unable to load system ROM (error "+d+": "+b+")");else{$a(a.Bb,b,c);if("["==c.charAt(0)||"{"==c.charAt(0))try{var e=eval("("+c+")"),f=e.bytes,h=e.data;if(f)a.u=f;else if(h)for(a.u=Array(4*h.length),d=c=0;c<h.length;c++)a.u[d++]=h[c]&255,a.u[d++]=h[c]>>8&255,a.u[d++]=h[c]>>16&255,a.u[d++]=h[c]>>24&255;else a.u=e;a.ta=e.symbols;if(!a.u.length){t("Empty ROM: "+b);return}if(1==a.u.length){t(a.u[0]);return}}catch(g){a.ka("ROM data error: "+g.message);return}else for(b=c.replace(/\n/gm,
" ").replace(/ +$/,"").split(" "),a.u=Array(b.length),e=0;e<b.length;e++)a.u[e]=aa(b[e],16);sd(a)}}
function sd(a){if(!ib(a))if(!a.G)A(a);else if(a.u&&a.B){if(a.u.length!=a.A)jb(a,"ROM size (0x"+p(a.u.length)+") does not match specified size ("+("0x"+p(a.A))+")");else{var b;b=a.H;if(rb(a.B,b,a.A,Ob)){for(var c=0;c<a.u.length;c++){var d=a.B,e=b+c;d.B[(e&d.A)>>>d.X].Wa(e&d.u,a.u[c]&255,e)}b=!0}else b=!1;if(b){b=[];"number"==typeof a.F?b.push(a.F):null!=a.F&&a.F.length&&(b=a.F);for(c=0;c<b.length;c++){for(var f=a,d=b[c],e=f.B,h=f.A,g=[],k=f.H>>>e.X;0<h&&k<e.B.length;)g.push(e.B[k++]),h-=e.ha;e=f.B;
f=f.A;h=0;for(d>>>=e.X;0<f&&d<e.B.length;){k=g[h++];if(!k)break;e.B[d++]=k;f-=e.ha}}delete a.u}}A(a)}}Ma(function(){for(var a=z(document,"pc8080","rom"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new qd(d);eb(d,c)}});function td(a){u.call(this,"RAM",a,td);this.F=a.addr;this.A=a.size;this.u=!1}x(td);m=td.prototype;m.Ma=function(a,b,c,d){this.B=b;this.b=c;this.C=d;A(this)};m.va=function(a,b){b||this.reset();return!0};m.ua=function(a){return a?this.save():!0};
m.reset=function(){!this.u&&this.A&&rb(this.B,this.F,this.A,1)&&(this.u=!0,this.status(Math.floor(this.A/1024)+"Kb allocated"));this.u||t("No RAM allocated")};m.save=function(){return null};m.restore=function(){return!0};Ma(function(){for(var a=z(document,"pc8080","ram"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new td(d);eb(d,c)}});function ud(a){u.call(this,"Keyboard",a,ud,65536);A(this)}x(ud);
Ma(function(){for(var a=z(document,"pc8080","keyboard"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new ud(d);eb(d,c)}});function vd(a){u.call(this,"Video",a,vd,262144);A(this)}x(vd);
Ma(function(){for(var a=z(document,"pc8080","video"),b=0;b<a.length;b++){var c=a[b],d=y(c),e=document.createElement("canvas");if(void 0===e||!e.getContext){c.innerHTML="<br/>Missing &lt;canvas&gt; support. Please try a newer web browser.";break}e.setAttribute("class","pcjs-canvas");e.setAttribute("width",d.screenWidth);e.setAttribute("height",d.screenHeight);e.style.backgroundColor=d.screenColor;e.style.height="auto";0<=ua().indexOf("MSIE")&&(c.onresize=function(a,b,c,d){return function(){b.style.height=
(a.clientWidth*d/c|0)+"px"}}(c,e,d.screenWidth,d.screenHeight),c.onresize());var f=+(d.aspect||Ra.aspect);f&&.3<=f&&3.33>=f&&(La("onresize",function(a,b,c){return function(){b.style.height=(a.clientWidth/c|0)+"px"}}(c,e,f)),window.onresize());c.appendChild(e);f=document.createElement("textarea");Aa("iOS")&&(f.setAttribute("autocapitalize","off"),f.setAttribute("autocorrect","off"));c.appendChild(f);e.getContext("2d");d=new vd(d);eb(d,c)}});
function wd(a){u.call(this,"Debugger",a,wd);this.ea=this.Ha=this.U=0;this.W=X();this.Ab=X();this.G=-1;this.F=[];this.pa=!1;this.ia=X();this.M=[];this.na={};this.A=this.Y=this.H=[];xd(this);this.ya=0;yd(this);this.Xa=[];zd(this,a.messages);this.Za=a.commands;var b=this;window?void 0===window.$&&(window.$=function(a){return nc(b,a)}):void 0===global.$&&(global.$=function(a){return nc(b,a)})}x(wd);
var Ad={"?":"help/print","a [#]":"assemble","b [#]":"breakpoint",c:"clear output","d [#]":"dump memory","e [#]":"edit memory",f:"frequencies","g [#]":"go [to #]",h:"halt","i [#]":"input port #","if":"eval expression",k:"stack trace",ln:"list nearest symbol(s)",m:"messages","o [#]":"output port #",p:"step over",print:"print expression",r:"dump/set registers",reset:"reset machine","t [#]":"trace","u [#]":"unassemble",x:"execution options",v:"print version","var":"assign variable"},Bd="NONE ACI ADC ADD ADI ANA ANI CALL CC CM CNC CNZ CP CPE CPO CZ CMA CMC CMP CPI DAA DAD DCR DCX DI EI HLT IN INR INX JMP JC JM JNC JNZ JP JPE JPO JZ LDA LDAX LHLD LXI MOV MVI NOP ORA ORI OUT PCHL POP PUSH RAL RAR RET RC RM RNC RNZ RP RPE RPO RZ RLC RRC RST SBB SBI SHLD SPHL STA STAX STC SUB SUI XCHG XRA XRI XTHL".split(" "),
Cd="B C D E H L M A F BC DE HL PSW SP PC".split(" "),Dd=[[45],[42,2323,32],[71,2387],[29,2323],[28,17],[22,17],[44,17,32],[63],[45,32768],[21,6419],[40,2387],[23,2323],[28,273],[22,273],[44,273,32],[64],[45,32768],[42,2579,32],[71,2643],[29,2579],[28,529],[22,529],[44,529,32],[52],[45,32768],[21,6675],[40,2643],[23,2579],[28,785],[22,785],[44,785,32],[53],[45,32768],[42,2835,32],[68,99],[29,2835],[28,1041],[22,1041],[44,1041,32],[20],[45,32768],[21,6931],[41,99],[23,2835],[28,1297],[22,1297],[44,
1297,32],[16],[45,32768],[42,3347,32],[70,97],[29,3347],[28,1553],[22,1553],[44,1553,32],[72],[45,32768],[21,7443],[39,97],[23,3347],[28,1809],[22,1809],[44,1809,32],[17],[43,17,17],[43,17,273],[43,17,529],[43,17,785],[43,17,1041],[43,17,1297],[43,17,1553],[43,17,1809],[43,273,17],[43,273,273],[43,273,529],[43,273,785],[43,273,1041],[43,273,1297],[43,273,1553],[43,273,1809],[43,529,17],[43,529,273],[43,529,529],[43,529,785],[43,529,1041],[43,529,1297],[43,529,1553],[43,529,1809],[43,785,17],[43,785,
273],[43,785,529],[43,785,785],[43,785,1041],[43,785,1297],[43,785,1553],[43,785,1809],[43,1041,17],[43,1041,273],[43,1041,529],[43,1041,785],[43,1041,1041],[43,1041,1297],[43,1041,1553],[43,1041,1809],[43,1297,17],[43,1297,273],[43,1297,529],[43,1297,785],[43,1297,1041],[43,1297,1297],[43,1297,1553],[43,1297,1809],[43,1553,17],[43,1553,273],[43,1553,529],[43,1553,785],[43,1553,1041],[43,1553,1297],[43,1553,1553],[43,1553,1809],[43,1809,17],[43,1809,273],[43,1809,529],[43,1809,785],[43,1809,1041],
[43,1809,1297],[43,1809,1553],[43,1809,1809],[3,17],[3,273],[3,529],[3,785],[3,1041],[3,1297],[3,1553],[3,1809],[2,17],[2,273],[2,529],[2,785],[2,1041],[2,1297],[2,1553],[2,1809],[73,17],[73,273],[73,529],[73,785],[73,1041],[73,1297],[73,1553],[73,1809],[66,17],[66,273],[66,529],[66,785],[66,1041],[66,1297],[66,1553],[66,1809],[5,17],[5,273],[5,529],[5,785],[5,1041],[5,1297],[5,1553],[5,1809],[76,17],[76,273],[76,529],[76,785],[76,1041],[76,1297],[76,1553],[76,1809],[46,17],[46,273],[46,529],[46,
785],[46,1041],[46,1297],[46,1553],[46,1809],[18,17],[18,273],[18,529],[18,785],[18,1041],[18,1297],[18,1553],[18,1809],[58],[50,2323],[34,35],[30,35],[11,35],[51,2323],[4,33],[65],[62],[54],[38,35],[30,32803],[15,35],[7,35],[1,33],[65],[57],[50,2579],[33,35],[48,33],[10,35],[51,2579],[74,33],[65],[55],[54,32768],[31,35],[27,33],[8,35],[7,32803],[67,33],[65],[61],[50,2835],[37,35],[78],[14,35],[51,2835],[6,33],[65],[60],[49],[36,35],[75],[13,35],[7,32803],[77,33],[65],[59],[50,3091],[35,35],[24],
[12,35],[51,3091],[47,33],[65],[56],[69],[32,35],[25],[9,35],[7,32803],[19,33],[65]],Ed={cpu:1,bus:64,mem:128,port:256,timer:2048,keyboard:65536,key:131072,video:262144,fdc:524288,disk:2097152,serial:8388608,speaker:33554432,computer:67108864,log:536870912,warn:1073741824,halt:-2147483648};m=wd.prototype;
m.Ma=function(a,b,c,d){this.B=b;this.b=c;this.u=a;(a=kc(a,"messages"))&&zd(this,a);this.kb=Dd;Fd(this,function(a){a:{var b=d.b.ja,c=a[0],g=a=0,k=b.length;if(c){a=Y(Z(d,c));if(-1===a){d.g("invalid address: "+c);break a}g=a>>>d.b.X;k=1}d.g("blockid physical blockaddr used size type");d.g("-------- --------- ---------- ------ ------ ----");for(var c=-1,l=0;k--;){var n=b[g];n.type==c?l++||d.g("..."):(c=n.type,l=Tb[c],n&&d.g(p(n.id)+" %"+p(g<<d.b.X)+" %%"+p(n.w)+" "+r(n.ib)+" "+r(n.size)+
" "+l),c!=Nb&&(c=-1),l=0);a+=d.b.ha;g++}}});A(this)};
m.la=function(a,b,c){var d=this;switch(b){case "debugInput":return this.sa=this.N[b]=c,c.onkeydown=function(a){var b;if(13==a.keyCode)b=c.value,c.value="",nc(d,b,!0);else if(27==a.keyCode)c.value=b="";else if(38==a.keyCode?d.G<d.F.length-1&&(b=d.F[++d.G]):40==a.keyCode&&(0<d.G?b=d.F[--d.G]:(b="",d.G=-1)),null!=b){var h=b.length;c.value=b;c.setSelectionRange(h,h)}null!=b&&a.preventDefault&&a.preventDefault()},!0;case "debugEnter":return this.N[b]=c,Da(c,function(){if(d.sa){var a=d.sa.value;d.sa.value=
"";nc(d,a,!0);return!0}return!1}),!0;case "step":return this.N[b]=c,Da(c,function(a){var b=!1;hb(d,!0)||(gb(d,!0),b=d.Ua(a?1:0),gb(d,!1));return b}),!0}return!1};m.hb=function(){this.sa&&this.sa.focus()};function Y(a){a=a&&a.w;null==a&&(a=-1);return a}m.wa=function(a,b){var c=255,d=Y(a);-1!==d&&(c=tb(this.B,d),b&&Gd(a,b));return c};m.jb=function(a,b){var c=65535,d=Y(a);if(-1!==d){var c=this.B,e=d&c.u,f=(d&c.A)>>>c.X,c=e!=c.u?c.B[f].ub(e,d):c.B[f++].gb(e,d)|c.B[f&c.V].gb(0,d+1)<<8;b&&Gd(a,b)}return c};
m.wb=function(a,b,c){var d=Y(a);if(-1!==d){var e=this.B;e.B[(d&e.A)>>>e.X].Wa(d&e.u,b&255,d);c&&Gd(a,c);D(this.b,!0)}};m.Rb=function(a,b,c){var d=Y(a);if(-1!==d){var e=this.B,f=d&e.u,h=(d&e.A)>>>e.X;f!=e.u?e.B[h].vb(f,b&65535,d):(e.B[h++].Wa(f,b&255,d),e.B[h&e.V].Wa(0,b>>8&255,d+1));c&&Gd(a,c);D(this.b,!0)}};function X(a){return{w:a||0,ra:!1}}function Hd(a){return[a.w,a.ra]}function Id(a){return{w:a[0],ra:a[1]}}
function Z(a,b,c){var d;c=(c?a.W:a.Ab).w;if(void 0!==b){d=b=Jd(a,b);var e;if(d.match(/^[a-z_][a-z0-9_]*$/i))for(d=d.toUpperCase(),c=0;c<a.M.length;c++){var f=a.M[c].ta[d];if(void 0!==f){d=f.o;void 0!==d&&(e=X(d));break}}if(d=e)return d;c=Kd(a,b,void 0)}null!=c&&(d=X(c));return d}function Ld(a,b,c){c&&(c=c.match(/(['"])(.*?)\1/))&&(b.Sb=Md(a,b.Ob=c[2]))}function Gd(a,b){null!=a.w&&(a.w+=b||1)}
function Nd(a,b,c){var d="";for(c=c||256;d.length<c;){var e=a.wa(b,1);if(!e||36==e||127<=e)break;d+=32<=e?String.fromCharCode(e):"."}return d}function zd(a,b){a.C=a;a.ga=a.Tb=1073741824;a.za=null;var c=Md(a,b.replace("keys","key").replace("kbd","keyboard"),!1,"|");if(c.length)for(var d in Ed)0<=la(c,d)&&(a.ga|=Ed[d],a.g(d+" messages enabled"))}function Fd(a,b){for(var c in Ed)if(64==Ed[c]){a.Xa[c]=b;break}}
function Od(a,b){var c;a=a.toUpperCase();null==b?c=la(Cd,a):(c=la(Cd,a.substr(b,3)),0>c&&(c=la(Cd,a.substr(b,2))));return c}function Pd(a,b){var c=0,d=Qd(a,b);if(void 0!==d)switch(b){case 7:case 0:case 1:case 2:case 3:case 4:case 5:case 8:c=2;break;case 9:case 10:case 11:case 12:case 13:case 14:c=4}return c?p(d,c):"??"}
function Qd(a,b){var c;if(0<=b){var d=a.b;switch(b){case 7:c=d.i;break;case 8:c=yc(d)&255;break;case 0:c=d.I;break;case 1:c=d.O;break;case 9:c=d.I<<8|d.O;break;case 2:c=d.J;break;case 3:c=d.P;break;case 10:c=d.J<<8|d.P;break;case 4:c=d.K;break;case 5:c=d.R;break;case 11:c=d.K<<8|d.R;break;case 12:c=d.i<<8|yc(d)&255;break;case 13:c=d.Z;break;case 14:c=d.L}}return c}
function Rd(a,b){b=Jd(a,b);for(var c=0,d,e;0<=(c=b.indexOf("@",c));)e=Od(b,c+1),0<=e&&(b=b.substr(0,c)+Pd(a,e)+b.substr(c+1+Cd[e].length)),c++;for(c=0;0<=(c=b.indexOf("#",c));)e=b.substr(c+1,2),d=aa(e,16),null!=d&&32<=d&&128>d?(d=e+" '"+String.fromCharCode(d)+"'",b=b.replace("#"+e,d),c+=d.length):c++;for(c=0;0<=(c=b.indexOf("$",c));)e=b.substr(c+1,9),(d=Z(a,e))?(d=e+' "'+Nd(a,d)+'"',b=b.replace("$"+e,d),c+=d.length):c++;for(c=0;0<=(c=b.indexOf("^",c));)e=b.substr(c+1,9),(d=Z(a,e))?(Gd(d),d=e+' "'+
Nd(a,d,11)+'"',b=b.replace("^"+e,d),c+=d.length):c++;return b}m.message=function(a,b){b&&(a+=" at "+p(X(this.b.L).w,4));if(!this.za||a!=this.za)if(this.za=a,this.ga&-2147483648&&(this.ca(),a+=" (cpu halted)"),this.g(a),this.b){var c=this.b;c.j.Ra=0;c.F-=c.b;c.b=0;D(c)}};function Fb(a,b,c,d){a.message(b.Ya+"."+(null!=d?"outPort":"inPort")+"("+r(c)+",unknown"+(null!=d?",0x"+p(d,2):"")+")")}
function yd(a){var b;if(kd(a)){if(!a.V||!a.V.length){a.V=Array(1E3);for(b=0;b<a.V.length;b++)a.V[b]=X();a.qa=0;a.g("instruction history buffer allocated")}if(!a.S||!a.S.length)for(a.S=Array(256),b=0;b<a.S.length;b++)a.S[b]=[b,0]}else a.V&&a.V.length&&a.g("instruction history buffer freed"),a.qa=0,a.V=[],a.S=[]}m.Ga=function(a){if(!Sd(this))return!1;this.b.Ga(a);return!0};
m.Ua=function(a,b,c){if(!Sd(this))return!1;this.U=0;a||kd(this)&&ld(this,this.b.L,0);try{var d=this.b.Ua(a);0<d&&(this.U+=d,sc(this.b,d,!0),pc(this.b,d),this.ea++)}catch(e){"number"!=typeof e&&(this.U=0,jb(this.b,e.stack||e.message))}!1!==c&&D(this.b);this.ma(b||!1);return 0<this.U};m.ca=function(a){this.b&&this.b.ca(a)};m.ma=function(a){void 0===a&&(a=!0);this.W=X(this.b.L);a&&1!=this.aa?Td(this):Ud(this)};
function Sd(a){var b;if(b=a.b&&ib(a.b))b=a.b,b.s.da?b=!0:(b.g(b.toString()+" not powered"),b=!1);b&&!hb(a.b)?(a=a.b,a.s.Ka?(a.g(a.toString()+" error"),a=!0):a=!1,a=!a):a=!1;return a}m.va=function(a,b){return!b&&(this.reset(!0),a&&this.restore&&!this.restore(a))?!1:!0};m.ua=function(a,b){b&&this.g(a?"suspending":"shutting down");return a?this.save():!0};m.reset=function(a){yd(this);this.ea=this.Ha=0;this.za=null;this.U=0;this.W=X(this.b.L);this.s.fa=!1;Vd(this);a||this.ma()};
m.save=function(){var a=new G(this);I(a,0,Hd(this.W));I(a,1,Hd(this.ia));I(a,2,[this.F,this.pa,this.ga]);I(a,3,this.M);return a.data()};m.restore=function(a){var b=0;void 0!==a[2]&&(this.W=Id(a[b++]),this.ia=Id(a[b++]),this.F=a[b][0],"string"==typeof this.F&&(this.F=[this.F]),this.pa=a[b][1],this.ga|=a[b][2]);a[3]&&(this.M=a[3]);return!0};m.start=function(a,b){this.aa||this.g("running");this.s.fa=!0;this.Ub=a;this.Xb=b};
m.stop=function(a,b){if(this.s.fa){this.s.fa=!1;this.U=b-this.Xb;if(!this.aa){var c="stopped";if(this.U){var d=a-this.Ub,e=0<d?Math.round(1E3*this.U/d):0,c=c+" (";kd(this)&&(c+=this.ea+" opcodes, ",this.Ha-=this.ea,this.ea=0);c+=this.U+" cycles, "+d+" ms, "+e+" hz)"}else fb(this,-2147483648)&&(c+=" (use the 't' command to execute blocked faults)");this.g(c)}this.ma(!0);this.hb();Vd(this,this.b.L)}};function kd(a){return 1<a.A.length||!!a.ya}
function ld(a,b,c){var d=a.b;if(0<c&&(a.ya&&!--a.ya||Xb(a,b,1,a.A)))return!0;0<=c&&a.S.length&&(a.ea++,b=tb(a.B,b),null!=b&&(a.S[b][1]++,b=a.V[a.qa],b.w=d.L,b.ra=!1,++a.qa==a.V.length&&(a.qa=0)));return!1}function Eb(a,b,c){a.g("break on input from port "+r(b)+": "+p(c));a.ca(!0)}function Ib(a,b,c){a.g("break on output to port "+r(b)+": "+p(c));a.ca(!0)}
function xd(a){var b,c;a.A=["bp"];if(void 0!==a.Y)for(b=1;b<a.Y.length;b++){c=a.Y[b];var d=a.b;Yb(d.ja[Y(c)>>>d.X],!1)}a.Y=["br"];if(void 0!==a.H)for(b=1;b<a.H.length;b++)c=a.H[b],d=a.b,Yb(d.ja[Y(c)>>>d.X],!0);a.H=["bw"];a.Cb=0}m.Aa=function(a,b,c){var d=!0;c||Wd(this,a,b,!1,!0);if(a!=this.A){var e=Y(b);if(-1===e)this.g("invalid address: "+p(b.w,4)),d=!1;else{var f=this.b;f.ja[e>>>f.X].Aa(e&f.G,a==this.H)}}d&&(a.push(b),c?b.ra=!0:(Xd(this,a,a.length-1,"set"),yd(this)));return d};
function Wd(a,b,c,d,e){var f=!1;c=Y(c);for(var h=1;h<b.length;h++){var g=b[h];if(c==Y(g)&&(!d||g.ra)){f=!0;g.ra||e||Xd(a,b,h,"cleared");b.splice(h,1);b!=a.A&&(d=a.b,Yb(d.ja[c>>>d.X],b==a.H));g.ra||yd(a);break}}return f}function Yd(a,b){for(var c=1;c<b.length;c++)Xd(a,b,c);return b.length-1}function Xd(a,b,c,d){c=b[c];a.g(b[0]+" "+p(c.w,4)+(d?" "+d:c.Ob?' "'+c.Ob+'"':""))}
function Vd(a,b){if(void 0!==b)Xb(a,b,1,a.A,!0),a.aa=0;else for(var c=1;c<a.A.length;c++){var d=a.A[c];if(d.ra){if(!Wd(a,a.A,d,!0))break;c=0}}}
function Xb(a,b,c,d,e){var f=!1;if(!a.Cb++)for(var h=1;!f&&h<d.length;h++){var g=d[h];if(!e||g.ra)for(var k=Y(g),l=0;l<c;l++)if(b+l==k){var n,f=!0;g.ra&&(Wd(a,d,g,!0),e=!0);if(n=g.Sb){for(var f=!1,q=0;q<n.length;q++)if(!Zd(a,n[q],!0)){if(n[q].indexOf("if")){f=!0;break}for(var v=q+1;v<n.length&&n[v].indexOf("else");v++)q++;if(v==n.length){f=!0;break}}a.b.s.fa||(f=!0)}if(f){e||Xd(a,d,h,"hit");break}}}a.Cb--;return f}
function $d(a,b,c,d){for(var e=X(b.w),f=a.wa(b,1),h=a.kb[f],f="",g=null,k=Bd[h[0]],l=h.length-1,n=1;n<=l;n++){var q="",v=h[n];if(void 0!==v){var R=v&15;if(0==R){if(null==g)continue;R=g}g=R;R=v&240;if(32==R){var q=a,R=b,H=" ";switch(v&15){case 1:v&12288&&(H=p(q.wa(R,1),2));break;case 2:H=p(q.wa(R,1)<<24>>24,4);break;case 3:H=p(q.jb(R,2),4);break;default:H="imm("+r(v)+")"}q=H}else 16==R&&(q=Cd[(v&3840)>>8]);if(!q||!q.length){f="INVALID";break}0<f.length&&(f+=",");f+=q||"???"}}h="";g=p(e.w,4)+" ";if(-1!==
e.w&&-1!==b.w){do if(h+=p(a.wa(e,1),2),null==e.w)break;while(e.w!=b.w)}g+=ga(h,11);g+=ga(k,7);f&&(g+=" "+f);c&&(g=ga(g,40)+";"+c,g=a.b.s.Ja?g+("cycles="+qc(a.b).toString()+" cs="+p(a.b.j.$a)):g+(null!=d?"="+d.toString():""));return g}function ae(a,b){var c;switch(b){case "I":c=a.b.oa&512;break;case "S":c=Fc(a.b);break;case "Z":c=Ec(a.b);break;case "A":c=Dc(a.b);break;case "P":c=N(a.b);break;case "C":c=M(a.b);break;default:c=0}return b+(c?"1":"0")+" "}
function be(a,b){return Cd[b]+"="+Pd(a,b)+" "}var ce={"||":0,"&&":1,"|":2,"^":3,"&":4,"!=":5,"==":5,">=":6,">":6,"<=":6,"<":6,">>>":7,">>":7,"<<":7,"-":8,"+":8,"%":9,"/":9,"*":9};
function de(a,b,c){for(c=c||-1;c--&&b.length;){var d=b.pop();if(2>a.length)return!1;var e=a.pop(),f=a.pop();switch(d){case "*":d=f*e;break;case "/":if(!e)return!1;d=f/e;break;case "%":if(!e)return!1;d=f%e;break;case "+":d=f+e;break;case "-":d=f-e;break;case "<<":d=f<<e;break;case ">>":d=f>>e;break;case ">>>":d=f>>>e;break;case "<":d=f<e?1:0;break;case "<=":d=f<=e?1:0;break;case ">":d=f>e?1:0;break;case ">=":d=f>=e?1:0;break;case "==":d=f==e?1:0;break;case "!=":d=f!=e?1:0;break;case "&":d=f&e;break;
v.prototype={constructor:v,parent:null,toString:function(){return this.name?this.name:this.id||this.type},ma:function(a,b,c){switch(b){case "clear":return this.R[b]||(this.R[b]=c,c.onclick=function(a){return function(){a.R.print&&(a.R.print.value="")}}(this)),!0;case "print":return this.R[b]||(this.Da=this.R[b]=c,c.value="",this.g=function(a){return function(b,c){8192<a.value.length&&(a.value=a.value.substr(a.value.length-4096));a.value+=(void 0!==c?c+": ":"")+(b||"")+"\n";a.scrollTop=a.scrollHeight}}(c),
this.ka=function(a,b,c){this.g(a,"notice",c)}),!0;default:return!1}},log:function(){},g:function(){},status:function(a){this.g(this.$a+": "+a)},ka:function(a,b){b||t(a)},ua:function(){return this.u.ga=!0},ta:function(a,b){b&&(this.u.ga=!1);return!0}};function gb(a,b,c,d,e,f){var h=!0;a.C&&(!0===h?h=0:null==h&&(h=a.fa),hb(a.C,a,b,c,d,e,f,h))}function ib(a,b){if(a.C){a===a.C?b|=0:b=b||a.fa;var c=a.C.fa&b;return!!b&&c===b||!!(c&a.C.Ub)}return!1}
function jb(a,b){if(a.u.rb)return a.u.La&&(a.u.La=!1),a.u.rb=!1;if(a.u.Na)return a.g(a.toString()+" error"),!1;a.u.La=b;return a.u.La}function kb(a,b){a.u.La&&(b?a.u.rb=!0:void 0===b&&a.g(a.toString()+" busy"));return a.u.La}function B(a){if(!a.u.Na&&(a.u.Oa=!0,a.u.Oa)){var b=a.nb;a.nb=null;b&&b()}}function lb(a,b){b&&(a.u.Oa?b():a.nb=b);return a.u.Oa}function mb(a,b){a.u.Na=!0;a.ka(b)}
var nb="undefined"!==typeof ArrayBuffer,ob=[1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,
0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1];function pb(a){v.call(this,"Panel",a,pb)}x(pb);m=pb.prototype;m.ma=function(a,b,c,d){return this.s&&this.s.ma(a,b,c,d)||this.b&&this.b.ma(a,b,c,d)||this.w&&this.w.ma(a,b,c,d)||this.C&&this.C.ma(a,b,c,d)?!0:this.parent.ma.call(this,a,b,c,d)};m.za=function(a,b,c,d){this.s=a;this.B=b;this.b=c;this.C=d;this.w=qb(a,"Keyboard")};m.ua=function(a,b){b||rb();return!0};m.ta=function(){return!0};m.oa=function(){};
function rb(){for(var a=!1,b=z(document,"pc8080","panel"),c=0;c<b.length;c++){var d=b[c],e=y(d),f;a:{f=e.id;if(void 0!==f)for(var h=void 0,h=0;h<w.length;h++)if(w[h].id===f){f=w[h];break a}f=null}f||(a=!0,f=new pb(e));db(f,d);a&&B(f)}}Ja(rb);
function sb(a,b,c){v.call(this,"Bus",a,sb);this.b=b;this.C=c;this.T=a.buswidth||16;this.Y=Math.pow(2,this.T);this.G=this.Y-1|0;this.X=20>=this.T?12:24>=this.T?14:15;this.ia=1<<this.X;this.Z=this.ia>>2;this.s=this.ia-1;this.S=this.Y/this.ia|0;this.W=this.S-1;this.w=[];this.D=[];this.H=this.I=!1;this.ba=[];this.ea=[];a=new C;tb(a,this.C);this.B=Array(this.S);for(b=0;b<this.S;b++)this.B[b]=a;a=this.b;b=this.B;c=this.X;var d=this.G;a.ja=b;a.X=c;a.ia=1<<a.X;a.G=a.ia-1;a.Y=b.length;a.W=a.Y-1;a.S=d;B(this)}
x(sb);sb.prototype.reset=function(){};sb.prototype.ua=function(a,b){b||this.reset();return!0};function ub(a,b,c,d){for(var e=b>>>a.X;0<c&&e<a.B.length;){var f=a.B[e],h=e*a.ia,g=c>a.ia?a.ia:c;if(f&&f.size){if(f.type==d){if(b+c<=f.A)return f.kb+=f.A-b,f.A=b,!0;if(b>=f.A+f.kb){g=f.size-(b-h);g>c&&(g=c);f.kb=b-f.A+g;c-=g;b=h+a.ia;continue}}return vb(1,b,c)}f=a.B[e];b=new C(b,g,a.ia,d);tb(b,a.C,f);a.B[e++]=b;b=h+a.ia;c-=g}return 0>=c?!0:vb(2,b,c)}
sb.prototype.U=function(a){return this.B[(a&this.G)>>>this.X].Ia(a&this.s,a)};function wb(a,b){return a.B[(b&a.G)>>>a.X].ib(b&a.s,b)}function Fb(a,b){if(void 0===b)return a.H=!a.H,a.H;void 0===a.w[b]&&(a.w[b]=[null,!1]);a.w[b][1]=!a.w[b][1];return a.w[b][1]}
function Gb(a,b){for(var c=1,d=0,e=0;0<c;){var f=a.w[b],h=a.ba[b]||1,g=1==h?255:2==h?65535:-1,k=g;void 0!==f?(f[0]&&(k=f[0](b,void 0),void 0===k?k=g:k&=g),a.C&&a.H!=f[1]&&Hb(a.C,b,k)):a.C&&(hb(a.C,a,b,null,void 0),a.H&&Hb(a.C,b,k));d|=k<<e;e+=h<<3;b+=h;c-=h}return d}function Ib(a,b){if(void 0===b)return a.I=!a.I,a.I;void 0===a.D[b]&&(a.D[b]=[null,!1]);a.D[b][1]=!a.D[b][1];return a.D[b][1]}
function Jb(a,b,c){for(var d=1,e=0;0<d;){var f=a.D[b],h=a.ea[b]||1,g=1==h?255:2==h?65535:-1,g=(c>>>=e)&g;if(void 0!==f){if(f[0])f[0](b,g,void 0);a.C&&a.I!=f[1]&&Kb(a.C,b,g)}else a.C&&(hb(a.C,a,b,g,void 0),a.I&&Kb(a.C,b,g));e+=h<<3;b+=h;d-=h}}function vb(a,b,c){t("Memory block error ("+a+": "+p(b)+","+p(c)+")");return!1}var Lb;if(nb){var Mb=new ArrayBuffer(2);(new DataView(Mb)).setUint16(0,256,!0);Lb=256===(new Uint16Array(Mb))[0]}else Lb=!1;var Nb=Lb;
function C(a,b,c,d){this.id=Ob+=2;this.b=null;this.A=a;this.kb=b;this.size=c||0;this.type=d||Pb;this.s=d==Qb;tb(this);this.ya=this.Wb=!1;if(c)if(nb)this.G=new ArrayBuffer(c),this.H=new DataView(this.G,0,c),this.B=new Uint8Array(this.G,0,c),this.S=new Uint16Array(this.G,0,c>>1),this.b=new Int32Array(this.G,0,c>>2),Rb(this,Nb?Sb:Tb);else{this.b=Array(c>>2);for(a=0;a<this.b.length;a++)this.b[a]=0;Rb(this,Ub)}else Rb(this)}var Pb=0,Qb=2,Vb=["NONE","RAM","ROM","VIDEO","H/W"],Ob=0;
C.prototype={constructor:C,parent:null,save:function(){var a,b;if(nb)for(a=Array(this.size>>2),b=0;b<a.length;b++)a[b]=this.H.getInt32(b<<2,!0);else a=this.b;return a},restore:function(a){if(a&&this.size==a.length<<2){var b;if(nb)for(b=0;b<a.length;b++)this.H.setInt32(b<<2,a[b],!0);else this.b=a;return this.ya=!0}return!1},Ca:function(a,b){b?0===this.w++&&Wb(this,Xb,!1):0===this.R++&&Yb(this,Xb,!1)},T:function(){this.C&&ib(this.C,129)&&this.C.message("attempt to read invalid block %"+p(this.A),!0);
return 255},D:function(a,b){this.C&&ib(this.C,129)&&this.C.message("attempt to write "+r(b)+" to invalid block %"+p(this.A),!0)},W:function(a,b){return this.Ia(a++,b++)|this.Ia(a,b)<<8},I:function(a,b,c){this.Xa(a++,b&255,c++);this.Xa(a,b>>8,c)},ea:function(a){return this.b[a>>2]>>>((a&3)<<3)&255},ra:function(a){var b=a>>2;a=(a&3)<<3;var c=this.b[b]>>a;return 24>a?c&65535:c&255|(this.b[b+1]&255)<<8},Ba:function(a,b){var c=a>>2,d=(a&3)<<3;this.b[c]=this.b[c]&~(255<<d)|b<<d;this.ya=!0},ab:function(a,
b){var c=a>>2,d=(a&3)<<3;24>d?this.b[c]=this.b[c]&~(65535<<d)|b<<d:(this.b[c]=this.b[c]&16777215|b<<24,c++,this.b[c]=this.b[c]&-256|b>>8);this.ya=!0},Z:function(a,b){if(this.C&&null!=this.A){var c=this.C;Zb(c,this.A+a,1,c.Z)&&c.da(!0)}return this.ib(a,b)},pa:function(a,b){if(this.C&&null!=this.A){var c=this.C;Zb(c,this.A+a,2,c.Z)&&c.da(!0)}return this.wb(a,b)},va:function(a,b,c){if(this.C&&null!=this.A){var d=this.C;Zb(d,this.A+a,1,d.H)&&d.da(!0)}this.s?this.D(a,b,c):this.Ya(a,b,c)},Za:function(a,
b,c){if(this.C&&null!=this.A){var d=this.C;Zb(d,this.A+a,2,d.H)&&d.da(!0)}this.s?this.D(a,b,c):this.xb(a,b,c)},Y:function(a){return this.B[a]},ba:function(a){return this.B[a]},na:function(a){return this.H.getUint16(a,!0)},qa:function(a){return a&1?this.B[a]|this.B[a+1]<<8:this.S[a>>1]},xa:function(a,b){this.B[a]=b;this.ya=!0},Aa:function(a,b){this.B[a]=b;this.ya=!0},Ka:function(a,b){this.H.setUint16(a,b,!0);this.ya=!0},$a:function(a,b){a&1?(this.B[a]=b,this.B[a+1]=b>>8):this.S[a>>1]=b;this.ya=!0}};
function tb(a,b,c){a.C=b;a.R=a.w=0;c&&((a.R=c.R)&&Yb(a,Xb,!1),(a.w=c.w)&&Wb(a,Xb,!1))}function $b(a,b){b?0===--a.w&&(a.Xa=a.s?a.D:a.Ya,a.Rb=a.s?a.I:a.xb):0===--a.R&&(a.Ia=a.ib,a.Pb=a.wb)}function Wb(a,b,c){c&&a.w||(a.Xa=!a.s&&b[2]||a.D,a.Rb=!a.s&&b[3]||a.I);if(c||void 0===c)a.Ya=b[2]||a.D,a.xb=b[3]||a.I}function Yb(a,b,c){c&&a.R||(a.Ia=b[0]||a.T,a.Pb=b[1]||a.W);if(c||void 0===c)a.ib=b[0]||a.T,a.wb=b[1]||a.W}function Rb(a,b){b||(b=ac);Yb(a,b,void 0);Wb(a,b,void 0)}
var ac=[],Ub=[C.prototype.ea,C.prototype.ra,C.prototype.Ba,C.prototype.ab],Xb=[C.prototype.Z,C.prototype.pa,C.prototype.va,C.prototype.Za];if(nb)var Tb=[C.prototype.Y,C.prototype.na,C.prototype.xa,C.prototype.Ka],Sb=[C.prototype.ba,C.prototype.qa,C.prototype.Aa,C.prototype.$a];
function bc(a,b){v.call(this,"CPU",a,bc,1);var c=a.cycles||b,d=a.multiplier||1;this.i={};this.i.Va=c;this.i.pb=0;this.i.Ha=d;this.i.tb=Math.round(this.i.Va/1E4)/100;this.i.Fa=this.i.tb*this.i.Ha;this.u.ha=!1;this.u.sb=!1;this.u.Ib=a.autoStart;this.u.Jb=!1;this.u.Ma=!1;this.i.bb=this.i.Sa=0;this.i.cb=a.csStart;this.i.Ra=a.csInterval;this.i.Ta=a.csStop;this.ea=this.Ja.bind(this);B(this)}x(bc);var lc=["power","reset"];m=bc.prototype;
m.za=function(a,b,c,d){this.s=a;this.B=b;this.C=d;for(b=0;b<lc.length;b++)(c=this.R[lc[b]])&&this.s.ma(null,lc[b],c);this.xa=(b=qb(a,"Video"))&&Math.max(b.xa,b.Xb)||60;this.T=qb(a,"ChipSet");a=mc(a,"autoStart");null!=a&&(this.u.Ib="true"==a?!0:"false"==a?!1:!!a);B(this)};m.reset=function(){this.i.pb=0};m.save=function(){return null};m.restore=function(){return!1};
m.ua=function(a,b){if(!b){if(a&&this.restore){nc(this);if(!this.restore(a))return!1;oc(this)}else this.reset();if(this.C){var c=this.C;c.g("Type ? for help with PC8080 Debugger commands");c.oa();if(c.ab){var d=c.ab;c.ab=null;pc(c,d)}}else this.g("No debugger detected")}D(this);return!0};m.ta=function(a){return a?this.save():!0};function qc(a){(a.u.Ib||!a.C&&void 0===a.R.run)&&a.Ja(!0)}m.Kb=function(){return 0};
function oc(a){void 0===a.i.cb&&(a.i.cb=0);void 0===a.i.Ra&&(a.i.Ra=-1);void 0===a.i.Ta&&(a.i.Ta=-1);a.u.Ma=0<=a.i.cb&&0<a.i.Ra;a.u.Ma&&(a.i.bb=0,a.i.Sa=a.i.cb-a.I)}function rc(a,b){if(a.u.Ma){var c=!1;a.i.bb=a.i.bb+a.Kb()|0;a.i.Sa-=b;0>=a.i.Sa&&(a.i.Sa+=a.i.Ra,c=!0);0<=a.i.Ta&&a.i.Ta<=sc(a)&&(a.i.Ra=a.i.Ta=-1,oc(a),a.da(),c=!0);c&&a.g(sc(a)+" cycles: checksum="+p(a.i.bb))}}
m.ma=function(a,b,c){var d=this;a=!1;switch(b){case "power":case "reset":this.R[b]=c;a=!0;break;case "run":this.R[b]=c;c.onclick=function(){var a;if(a=d.s)if(a=d.s,a.u.ga)a=!0;else{var b=null,c,g=Za(a.id);for(c=0;c<g.length&&(b=g[c],b===a||b.u.Oa);c++);if(c==g.length)for(c=0;c<g.length&&(b=g[c],b===a||b.u.ga);c++);c==g.length&&(b=a);t("The "+b.type+" component ("+b.id+") is not "+(b.u.Oa?"powered yet":"ready yet"+(b.nb?" (waiting for notification)":""))+".");a=!1}a&&(d.u.ha?d.da(!0):d.Ja(!0))};a=
!0;break;case "speed":this.R[b]=c;a=!0;break;case "setSpeed":this.R[b]=c,c.onclick=function(){tc(d,d.i.Ha<<1,!0)},c.textContent=this.i.Fa.toFixed(2)+"Mhz",a=!0}return a};function uc(a,b,c){a.I+=b;c&&(a.D=a.b=0)}
function vc(a,b){var c=30;c<a.xa&&(c=a.xa);2>c&&(c=2);var d=1;b&&1<a.i.Ha&&a.i.Ea&&(d=a.i.Ea/a.i.tb);a.i.Lb=Math.round(1E3/30);a.i.fc=Math.floor(a.i.Va/c*d);a.i.ub=Math.floor(a.i.Va/30*d);a.i.Nb=Math.floor(a.i.Va/a.xa*d);a.i.Mb=Math.floor(a.i.Va/2*d);b||(a.i.Ua=a.i.ub,a.i.fb=a.i.Nb,a.i.eb=a.i.Mb);a.i.vb=0}function sc(a){return a.I+a.H+a.D-a.b}function nc(a){a.i.Ea=0;a.I=a.H=a.D=a.b=0;oc(a);tc(a,1)}
function tc(a,b,c){var d=!1;if(void 0!==b){.8>a.i.Ea/a.i.Fa?b=1:d=!0;a.i.Ha=b;b=a.i.tb*a.i.Ha;if(a.i.Fa!=b){a.i.Fa=b;b=a.i.Fa.toFixed(2)+"Mhz";var e=a.R.setSpeed;e&&(e.textContent=b);a.g("target speed: "+b)}c&&a.s&&a.s.jb()}uc(a,a.H);a.H=0;a.i.Qa=ja();a.i.Ga=0;vc(a);return d}
m.Ja=function(a){if(jb(this,!0)){if(!this.u.ha){tc(this);this.s&&this.s.start(this.i.Qa,sc(this));this.u.ha=!0;this.u.sb=!0;this.T&&this.T.kc();var b=this.R.run;b&&(b.textContent="Halt");this.s&&(this.s.oa(!0),a&&this.s.jb(!0))}this.i.vb>=this.i.Va&&vc(this,!0);this.i.gb=0;this.i.ob=ja();this.i.Ga&&(a=this.i.ob-this.i.Ga,a>this.i.Lb&&(this.i.Qa+=a,this.i.Qa>this.i.ob&&(this.i.Qa=this.i.ob)));try{do{var c=this.u.Ma?1:this.i.fc;try{this.Wa(c)}catch(e){if("number"!=typeof e)throw e;}var d=this.D-this.b;
this.H+=d;this.i.gb+=d;uc(this,0,!0);rc(this,d);this.i.fb-=d;0>=this.i.fb&&(this.i.fb+=this.i.Nb,this.s&&wc(this.s,this.i.pb++),this.i.pb>this.xa&&(this.i.pb=0));this.i.eb-=d;0>=this.i.eb&&(this.i.eb+=this.i.Mb,this.s&&this.s.oa());this.i.Ua-=d;if(0>=this.i.Ua){this.i.Ua+=this.i.ub;break}}while(this.u.ha)}catch(e){this.da();D(this);this.s&&this.s.stop(ja(),sc(this));jb(this,!1);mb(this,e.stack||e.message);return}c=setTimeout;d=this.ea;this.i.Ga=ja();a=this.i.Lb;this.i.gb&&(a=Math.round(a*this.i.gb/
this.i.ub));a-=this.i.Ga-this.i.ob;if(b=this.i.Ga-this.i.Qa)this.i.Ea=Math.round(this.H/(10*b))/100,864E5<=b&&(this.I=0,tc(this));if(0>a||this.i.Ea<this.i.Fa)a=0;this.i.vb+=this.i.gb;this.i.Ga+=a;c(d,a)}else D(this),this.s&&this.s.stop(ja(),sc(this))};m.Wa=function(){return 0};m.da=function(a){kb(this,!0);this.D-=this.b;this.b=0;uc(this,this.H);this.H=0;if(this.u.ha){this.u.ha=!1;this.T&&this.T.kc();var b=this.R.run;b&&(b.textContent="Run")}this.u.mb=a};
function D(a,b){a.s&&(wc(a.s,-1),a.s.oa(b))}function xc(a){this.Pa=a.model||8080;bc.call(this,a,1E6);this.Z=yc;nc(this);this.u.mb=this.u.Vb=!1;this.ba=0;this.ja=[];this.X=this.ia=this.G=this.Y=this.W=this.S=0;zc(this)}x(xc,bc);m=xc.prototype;m.reset=function(){this.u.ha&&this.da();zc(this);nc(this);this.u.Na=!1;this.parent.reset.call(this)};function zc(a){a.j=0;a.K=0;a.N=0;a.L=0;a.O=0;a.M=0;a.P=0;a.aa=0;E(a,0);Ac(a,0);a.w=0}
m.Kb=function(){var a=this.j+this.K+this.N+this.L+this.O+this.M+this.P|0;return a=a+this.aa+this.J+Bc(this)|0};
m.save=function(){var a=new G(this);H(a,0,[this.j,this.K,this.N,this.L,this.O,this.M,this.P,this.aa,this.J,Bc(this)]);H(a,1,[this.w,this.I,this.i.Ha]);for(var b=this.B,c=0,d=[],e=0;e<b.S;e++){var f=b.B[e];if(f.ya||f.Wb){d[c++]=e;var h=c++;a:if(f=f.save()){for(var g=0,k=0,l=[];g<f.length;){for(var n=f[g],q=g+1;q<f.length&&f[q]===n;)q++;l[k++]=q-g;l[k++]=n;g=q}if(l.length<f.length){f=l;break a}}d[h]=f}}H(a,2,d);return a.data()};
m.restore=function(a){var b=a[0];this.j=b[0];this.K=b[1];this.N=b[2];this.L=b[3];this.O=b[4];this.M=b[5];this.P=b[6];this.aa=b[7]&65535;E(this,b[8]);Ac(this,b[9]);b=a[1];this.w=b[0];this.I=b[1];tc(this,b[3]);a:{b=this.B;a=a[2];var c;for(c=0;c<a.length-1;c+=2){var d=a[c],e=a[c+1];if(e&&e.length<b.Z){for(var f=0,h=Array(b.Z),g=0;g<e.length-1;)for(var k=e[g++],l=e[g++];k--;)h[f++]=l;e=h}f=b.B[d];if(!f||!f.restore(e)){t("Unable to restore memory block "+d);b=!1;break a}}b=!0}return b};
m.ma=function(a,b,c){var d=!1;switch(b){case "A":case "B":case "C":case "D":case "E":case "H":case "L":case "SP":case "PC":case "F":case "SF":case "ZF":case "AF":case "PF":case "CF":this.R[b]=c;this.ba++;d=!0;break;default:d=this.parent.ma.call(this,a,b,c)}return d};function Cc(a){return a.K<<8|a.N}function Dc(a,b){a.K=b>>8&255;a.N=b&255}function Ec(a){return a.L<<8|a.O}function Fc(a,b){a.L=b>>8&255;a.O=b&255}function I(a){return a.M<<8|a.P}function J(a,b){a.M=b>>8&255;a.P=b&255}
function E(a,b){a.J=b&65535}function K(a){return a.F&256?1:0}function Gc(a){return ob[a.V&255]?4:0}function Hc(a){return(a.V^a.ca)&16?16:0}function Ic(a){return a.F&255?0:64}function Jc(a){return a.V&128?128:0}function Bc(a){return a.la&-214|Jc(a)|Ic(a)|Hc(a)|Gc(a)|K(a)}function Ac(a,b){a.F=a.V=a.ca=0;b&1&&(a.F|=256);b&4||(a.V|=1);b&16&&(a.ca|=16);b&64||(a.F|=255);b&128&&(a.V^=192);a.la=a.la&-513|b&512|2}function Kc(a,b){a.ca=a.j^b;return(a.F=a.V=a.j+b)&255}
function Lc(a,b){a.ca=a.j^b;return(a.F=a.V=a.j+b+(a.F&256?1:0))&255}function Mc(a,b){return a.F=a.V=a.ca=a.j&b}function fd(a,b){a.ca=a.j^b;a.F=a.V=a.j-b}function gd(a,b){a.ca=b;b=(a.V=b-1)&255;a.F=a.F&-256|b;return b}function hd(a,b){a.ca=b;b=(a.V=b+1)&255;a.F=a.F&-256|b;return b}function id(a,b){return a.F=a.V=a.ca=a.j|b}function jd(a,b){a.ca=a.j^b;return(a.F=a.V=a.j-b)&255}function kd(a,b){a.ca=a.j^b;return(a.F=a.V=a.j-b-(a.F&256?1:0))&255}function ld(a,b){return a.F=a.V=a.ca=a.j^b}
m.U=function(a){return this.ja[(a&this.S)>>>this.X].Ia(a&this.G,a)};function md(a,b){var c=b&a.G,d=(b&a.S)>>>a.X;if(c<a.G)return a.ja[d].Pb(c,b);c=a.ja[d].Ia(c,b);return c|=a.ja[d+1&a.W].Ia(0,b+1)<<8}function L(a,b,c){a.ja[(b&a.S)>>>a.X].Xa(b&a.G,c&255,b)}function nd(a,b,c){var d=b&a.G,e=(b&a.S)>>>a.X;d<a.G?a.ja[e].Rb(d,c&65535,b):(a.ja[e++].Xa(d,c&255,b),a.ja[e&a.W].Xa(0,c>>8&255,b+1))}function M(a){var b=a.U(a.J);E(a,a.J+1);return b}function O(a){var b=md(a,a.J);E(a,a.J+2);return b}
function P(a){var b=md(a,a.aa);a.aa=a.aa+2&65535;return b}function Q(a,b){a.aa=a.aa-2&65535;nd(a,a.aa,b)}function T(a,b,c,d){d=d||2;a.R[b]&&(void 0===c&&(mb(a,"Value for "+b+" is invalid"),a.da()),c=!a.u.ha||a.u.Jb?p(c,d):"--------".substr(0,d),a.R[b].textContent!=c&&(a.R[b].textContent=c))}
m.oa=function(a){this.ba&&(a||!this.u.ha||this.u.Jb)&&(T(this,"A",this.j),T(this,"B",this.K),T(this,"C",this.N),T(this,"D",this.L),T(this,"E",this.O),T(this,"H",this.M),T(this,"L",this.P),T(this,"SP",this.aa,4),T(this,"PC",this.J,4),a=Bc(this),T(this,"F",a,2),T(this,"SF",a&128,1),T(this,"ZF",a&64,1),T(this,"AF",a&16,1),T(this,"PF",a&4,1),T(this,"CF",a&1,1));if(a=this.R.speed)a.textContent=this.u.ha&&this.i.Ea?this.i.Ea.toFixed(2)+"Mhz":"Stopped"};
m.Wa=function(a){this.u.mb=!0;var b=this.u.Vb=this.C&&od(this.C),c=a?this.u.sb?0:1:-1;this.u.sb=!1;this.D=this.b=a;do{if(this.w){var d;this.w&8&&this.la&512?(d=199|(this.w&7)<<3,this.w&=-16,this.la&=-513,this.Z[d].call(this),d=!0):d=!1;if(d){if(!a){this.g("interrupt dispatched");break}}else if(this.w&16){this.b=0;break}}if(b){if(pd(this.C,this.J,c)){this.da();break}c=1}this.Z[M(this)].call(this)}while(0<this.b);return this.u.mb?this.D-this.b:void 0===this.u.mb?0:-1};
Ja(function(){for(var a=z(document,"pc8080","cpu"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new xc(d);db(d,c)}});function qd(){this.b-=4}function rd(){E(this,O(this));this.b-=10}function sd(){E(this,P(this));this.b-=10}function td(){var a=O(this);Q(this,this.J);E(this,a);this.b-=17}
var yc=[qd,function(){Dc(this,O(this));this.b-=10},function(){L(this,Cc(this),this.j);this.b-=7},function(){Dc(this,Cc(this)+1);this.b-=5},function(){this.K=hd(this,this.K);this.b-=5},function(){this.K=gd(this,this.K);this.b-=5},function(){this.K=M(this);this.b-=7},function(){var a=this.j<<1;this.j=a&255|a>>8;this.F=this.F&255|a&256;this.b-=4},qd,function(){var a;J(this,a=I(this)+Cc(this));this.F=this.F&255|a>>8&256;this.b-=10},function(){this.j=this.U(Cc(this));this.b-=7},function(){Dc(this,Cc(this)-
1);this.b-=5},function(){this.N=hd(this,this.N);this.b-=5},function(){this.N=gd(this,this.N);this.b-=5},function(){this.N=M(this);this.b-=7},function(){var a=this.j<<8&256;this.j=(a|this.j)>>1;this.F=this.F&255|a;this.b-=4},qd,function(){Fc(this,O(this));this.b-=10},function(){L(this,Ec(this),this.j);this.b-=7},function(){Fc(this,Ec(this)+1);this.b-=5},function(){this.L=hd(this,this.L);this.b-=5},function(){this.L=gd(this,this.L);this.b-=5},function(){this.L=M(this);this.b-=7},function(){var a=this.j<<
1;this.j=a&255|this.F>>8;this.F=this.F&255|a&256;this.b-=4},qd,function(){var a;J(this,a=I(this)+Ec(this));this.F=this.F&255|a>>8&256;this.b-=10},function(){this.j=this.U(Ec(this));this.b-=7},function(){Fc(this,Ec(this)-1);this.b-=5},function(){this.O=hd(this,this.O);this.b-=5},function(){this.O=gd(this,this.O);this.b-=5},function(){this.O=M(this);this.b-=7},function(){var a=this.j<<8&256;this.j=(this.F&256|this.j)>>1;this.F=this.F&255|a;this.b-=4},qd,function(){J(this,O(this));this.b-=10},function(){nd(this,
O(this),I(this));this.b-=16},function(){J(this,I(this)+1);this.b-=5},function(){this.M=hd(this,this.M);this.b-=5},function(){this.M=gd(this,this.M);this.b-=5},function(){this.M=M(this);this.b-=7},function(){var a=this.j,b=!!K(this),c=!!Hc(this);9<(a&15)||c?(a+=6,c=!0):c=!1;160<=a||b?(a+=96,b=!0):b=!1;this.F=this.V=this.j=a&255;this.F=b?this.F|256:this.F&-257;this.ca=c?~this.V&16|this.ca&-17:this.V&16|this.ca&-17;this.b-=4},qd,function(){var a;J(this,a=I(this)+I(this));this.F=this.F&255|a>>8&256;this.b-=
10},function(){J(this,md(this,O(this)));this.b-=16},function(){J(this,I(this)-1);this.b-=5},function(){this.P=hd(this,this.P);this.b-=5},function(){this.P=gd(this,this.P);this.b-=5},function(){this.P=M(this);this.b-=7},function(){this.j=~this.j&255;this.b-=4},qd,function(){this.aa=O(this)&65535;this.b-=10},function(){L(this,O(this),this.j);this.b-=13},function(){this.aa=this.aa+1&65535;this.b-=5},function(){var a=I(this);L(this,a,hd(this,this.U(a)));this.b-=10},function(){var a=I(this);L(this,a,gd(this,
this.U(a)));this.b-=10},function(){L(this,I(this),M(this));this.b-=10},function(){this.F|=256;this.b-=4},qd,function(){var a;this.aa=(a=I(this)+this.aa)&65535;this.F=this.F&255|a>>8&256;this.b-=10},function(){this.j=this.U(O(this));this.b-=13},function(){this.aa=this.aa-1&65535;this.b-=5},function(){this.j=hd(this,this.j);this.b-=5},function(){this.j=gd(this,this.j);this.b-=5},function(){this.j=M(this);this.b-=7},function(){this.F=K(this)?this.F&-257:this.F|256;this.b-=4},function(){this.b-=5},function(){this.K=
this.N;this.b-=5},function(){this.K=this.L;this.b-=5},function(){this.K=this.O;this.b-=5},function(){this.K=this.M;this.b-=5},function(){this.K=this.P;this.b-=5},function(){this.K=this.U(I(this));this.b-=7},function(){this.K=this.j;this.b-=5},function(){this.N=this.K;this.b-=5},function(){this.b-=5},function(){this.N=this.L;this.b-=5},function(){this.N=this.O;this.b-=5},function(){this.N=this.M;this.b-=5},function(){this.N=this.P;this.b-=5},function(){this.N=this.U(I(this));this.b-=7},function(){this.N=
this.j;this.b-=5},function(){this.L=this.K;this.b-=5},function(){this.L=this.N;this.b-=5},function(){this.b-=5},function(){this.L=this.O;this.b-=5},function(){this.L=this.M;this.b-=5},function(){this.L=this.P;this.b-=5},function(){this.L=this.U(I(this));this.b-=7},function(){this.L=this.j;this.b-=5},function(){this.O=this.K;this.b-=5},function(){this.O=this.N;this.b-=5},function(){this.O=this.L;this.b-=5},function(){this.b-=5},function(){this.O=this.M;this.b-=5},function(){this.O=this.P;this.b-=5},
function(){this.O=this.U(I(this));this.b-=7},function(){this.O=this.j;this.b-=5},function(){this.M=this.K;this.b-=5},function(){this.M=this.N;this.b-=5},function(){this.M=this.L;this.b-=5},function(){this.M=this.O;this.b-=5},function(){this.b-=5},function(){this.M=this.P;this.b-=5},function(){this.M=this.U(I(this));this.b-=7},function(){this.M=this.j;this.b-=5},function(){this.P=this.K;this.b-=5},function(){this.P=this.N;this.b-=5},function(){this.P=this.L;this.b-=5},function(){this.P=this.O;this.b-=
5},function(){this.P=this.M;this.b-=5},function(){this.b-=5},function(){this.P=this.U(I(this));this.b-=7},function(){this.P=this.j;this.b-=5},function(){L(this,I(this),this.K);this.b-=7},function(){L(this,I(this),this.N);this.b-=7},function(){L(this,I(this),this.L);this.b-=7},function(){L(this,I(this),this.O);this.b-=7},function(){L(this,I(this),this.M);this.b-=7},function(){L(this,I(this),this.P);this.b-=7},function(){this.w|=16;this.b-=7;this.C&&ib(this,-2147483648)?(E(this,this.J-1),this.C.da()):
this.la&512||(this.C&&E(this,this.J-1),this.da())},function(){L(this,I(this),this.j);this.b-=7},function(){this.j=this.K;this.b-=5},function(){this.j=this.N;this.b-=5},function(){this.j=this.L;this.b-=5},function(){this.j=this.O;this.b-=5},function(){this.j=this.M;this.b-=5},function(){this.j=this.P;this.b-=5},function(){this.j=this.U(I(this));this.b-=7},function(){this.b-=5},function(){this.j=Kc(this,this.K);this.b-=4},function(){this.j=Kc(this,this.N);this.b-=4},function(){this.j=Kc(this,this.L);
this.b-=4},function(){this.j=Kc(this,this.O);this.b-=4},function(){this.j=Kc(this,this.M);this.b-=4},function(){this.j=Kc(this,this.P);this.b-=4},function(){this.j=Kc(this,this.U(I(this)));this.b-=7},function(){this.j=Kc(this,this.j);this.b-=4},function(){this.j=Lc(this,this.K);this.b-=4},function(){this.j=Lc(this,this.N);this.b-=4},function(){this.j=Lc(this,this.L);this.b-=4},function(){this.j=Lc(this,this.O);this.b-=4},function(){this.j=Lc(this,this.M);this.b-=4},function(){this.j=Lc(this,this.P);
this.b-=4},function(){this.j=Lc(this,this.U(I(this)));this.b-=7},function(){this.j=Lc(this,this.j);this.b-=4},function(){this.j=jd(this,this.K);this.b-=4},function(){this.j=jd(this,this.N);this.b-=4},function(){this.j=jd(this,this.L);this.b-=4},function(){this.j=jd(this,this.O);this.b-=4},function(){this.j=jd(this,this.M);this.b-=4},function(){this.j=jd(this,this.P);this.b-=4},function(){this.j=jd(this,this.U(I(this)));this.b-=7},function(){this.j=jd(this,this.j);this.b-=4},function(){this.j=kd(this,
this.K);this.b-=4},function(){this.j=kd(this,this.N);this.b-=4},function(){this.j=kd(this,this.L);this.b-=4},function(){this.j=kd(this,this.O);this.b-=4},function(){this.j=kd(this,this.M);this.b-=4},function(){this.j=kd(this,this.P);this.b-=4},function(){this.j=kd(this,this.U(I(this)));this.b-=7},function(){this.j=kd(this,this.j);this.b-=4},function(){this.j=Mc(this,this.K);this.b-=4},function(){this.j=Mc(this,this.N);this.b-=4},function(){this.j=Mc(this,this.L);this.b-=4},function(){this.j=Mc(this,
this.O);this.b-=4},function(){this.j=Mc(this,this.M);this.b-=4},function(){this.j=Mc(this,this.P);this.b-=4},function(){this.j=Mc(this,this.U(I(this)));this.b-=7},function(){this.j=Mc(this,this.j);this.b-=4},function(){this.j=ld(this,this.K);this.b-=4},function(){this.j=ld(this,this.N);this.b-=4},function(){this.j=ld(this,this.L);this.b-=4},function(){this.j=ld(this,this.O);this.b-=4},function(){this.j=ld(this,this.M);this.b-=4},function(){this.j=ld(this,this.P);this.b-=4},function(){this.j=ld(this,
this.U(I(this)));this.b-=7},function(){this.j=ld(this,this.j);this.b-=4},function(){this.j=id(this,this.K);this.b-=4},function(){this.j=id(this,this.N);this.b-=4},function(){this.j=id(this,this.L);this.b-=4},function(){this.j=id(this,this.O);this.b-=4},function(){this.j=id(this,this.M);this.b-=4},function(){this.j=id(this,this.P);this.b-=4},function(){this.j=id(this,this.U(I(this)));this.b-=7},function(){this.j=id(this,this.j);this.b-=4},function(){fd(this,this.K);this.b-=4},function(){fd(this,this.N);
this.b-=4},function(){fd(this,this.L);this.b-=4},function(){fd(this,this.O);this.b-=4},function(){fd(this,this.M);this.b-=4},function(){fd(this,this.P);this.b-=4},function(){fd(this,this.U(I(this)));this.b-=7},function(){fd(this,this.j);this.b-=4},function(){Ic(this)||(E(this,P(this)),this.b-=6);this.b-=5},function(){Dc(this,P(this));this.b-=10},function(){var a=O(this);Ic(this)||E(this,a);this.b-=10},rd,function(){var a=O(this);Ic(this)||(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},function(){Q(this,
Cc(this));this.b-=11},function(){this.j=Kc(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,0);this.b-=11},function(){Ic(this)&&(E(this,P(this)),this.b-=6);this.b-=5},sd,function(){var a=O(this);Ic(this)&&E(this,a);this.b-=10},rd,function(){var a=O(this);Ic(this)&&(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},td,function(){this.j=Lc(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,8);this.b-=11},function(){K(this)||(E(this,P(this)),this.b-=6);this.b-=5},function(){Fc(this,P(this));
this.b-=10},function(){var a=O(this);K(this)||E(this,a);this.b-=10},function(){var a=M(this);Jb(this.B,a,this.j);this.b-=10},function(){var a=O(this);K(this)||(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},function(){Q(this,Ec(this));this.b-=11},function(){this.j=jd(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,16);this.b-=11},function(){K(this)&&(E(this,P(this)),this.b-=6);this.b-=5},sd,function(){var a=O(this);K(this)&&E(this,a);this.b-=10},function(){var a=M(this);this.j=Gb(this.B,
a)&255;this.b-=10},function(){var a=O(this);K(this)&&(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},td,function(){this.j=kd(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,24);this.b-=11},function(){Gc(this)||(E(this,P(this)),this.b-=6);this.b-=5},function(){J(this,P(this));this.b-=10},function(){var a=O(this);Gc(this)||E(this,a);this.b-=10},function(){var a=P(this);Q(this,I(this));J(this,a);this.b-=18},function(){var a=O(this);Gc(this)||(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},
function(){Q(this,I(this));this.b-=11},function(){this.j=Mc(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,32);this.b-=11},function(){Gc(this)&&(E(this,P(this)),this.b-=6);this.b-=5},function(){E(this,I(this));this.b-=5},function(){var a=O(this);Gc(this)&&E(this,a);this.b-=10},function(){var a=I(this);J(this,Ec(this));Fc(this,a);this.b-=5},function(){var a=O(this);Gc(this)&&(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},td,function(){this.j=ld(this,M(this));this.b-=7},function(){Q(this,
this.J);E(this,40);this.b-=11},function(){Jc(this)||(E(this,P(this)),this.b-=6);this.b-=5},function(){var a=P(this);Ac(this,a);this.j=a>>8;this.b-=10},function(){var a=O(this);Jc(this)||E(this,a);this.b-=10},function(){this.la&=-513;this.b-=4},function(){var a=O(this);Jc(this)||(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},function(){Q(this,Bc(this)&255|this.j<<8);this.b-=11},function(){this.j=id(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,48);this.b-=11},function(){Jc(this)&&(E(this,
P(this)),this.b-=6);this.b-=5},function(){this.aa=I(this)&65535;this.b-=5},function(){var a=O(this);Jc(this)&&E(this,a);this.b-=10},function(){this.la|=512;this.b-=4},function(){var a=O(this);Jc(this)&&(Q(this,this.J),E(this,a),this.b-=6);this.b-=11},td,function(){fd(this,M(this));this.b-=7},function(){Q(this,this.J);E(this,56);this.b-=11}];
function U(a){v.call(this,"ChipSet",a,U,32768);var b=a.model;b&&!ud[b]&&t("Unrecognized ChipSet model: "+b);this.Pa=ud[b];a.sound&&(this.W=null,window&&(this.W=window.AudioContext||window.webkitAudioContext),this.W&&new this.W);B(this)}x(U);var ud={SI1978:1978.1};m=U.prototype;m.ma=function(){return!1};
m.za=function(a,b,c,d){this.B=b;this.b=c;this.C=d;this.s=a;if(1978.1==this.Pa){var e;a=vd;void 0===e&&(e=0);for(var f in a){c=b;d=+f+e;var h=a[f].bind(this);if(void 0!==h)for(var g=+f+e;g<=d;g++)void 0!==c.w[g]?t("Input port "+r(g)+" already registered"):c.w[g]=[h,!1]}var k;e=wd;void 0===k&&(k=0);for(var l in e)if(f=b,a=+l+k,c=e[l].bind(this),void 0!==c)for(d=+l+k;d<=a;d++)void 0!==f.D[d]?t("Output port "+r(d)+" already registered"):f.D[d]=[c,!1]}};
m.ua=function(a,b){if(!b)if(!a)this.reset();else if(!this.restore(a))return!1;return!0};m.ta=function(a){return a?this.save():!0};m.reset=function(){this.G=this.H=this.w=this.D=this.T=this.S=this.I=0};m.save=function(){var a=new G(this);1978.1==this.Pa&&H(a,0,[this.I,this.S,this.T,this.D,this.w,this.G,this.H]);return a.data()};m.restore=function(a){a=a[0];1978.1==this.Pa&&(this.I=a[0],this.S=a[1],this.T=a[2],this.D=a[3],this.w=a[4],this.G=a[5],this.H=a[6]);return!0};
m.bc=function(a,b){var c=this.I;gb(this,a,null,b,"STATUS0",c);return c};m.cc=function(a,b){var c=this.S;gb(this,a,null,b,"STATUS1",c);return c};m.dc=function(a,b){var c=this.T;gb(this,a,null,b,"STATUS2",c);return c};m.ac=function(a,b){var c=this.D<<this.w>>8&255;gb(this,a,null,b,"SHIFT.RESULT",c);return c};m.gc=function(a,b,c){gb(this,a,b,c,"SHIFT.COUNT",null);this.w=b};m.ic=function(a,b,c){gb(this,a,b,c,"SOUND1",null);this.G=b};m.hc=function(a,b,c){gb(this,a,b,c,"SHIFT.DATA",null);this.D=b};
m.jc=function(a,b,c){gb(this,a,b,c,"SOUND2",null);this.H=b};var vd={0:U.prototype.bc,1:U.prototype.cc,2:U.prototype.dc,3:U.prototype.ac},wd={2:U.prototype.gc,3:U.prototype.ic,4:U.prototype.hc,5:U.prototype.jc};Ja(function(){for(var a=z(document,"pc8080","chipset"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new U(d);db(d,c)}});
function xd(a){v.call(this,"ROM",a,xd);this.s=null;this.H=a.addr;this.w=a.size;this.D=a.alias;this.G=a.file;this.I=ba(this.G);if(this.G){a=this.G;var b=ca(this.I);"json"!=b&&"hex"!=b&&(a=na()+"/api/v1/dump?file="+this.G+"&format=bytes&decimal=true");var c=this;ma(a,null,!0,function(a,b,f){yd(c,a,b,f)})}}x(xd);xd.prototype.za=function(a,b,c,d){this.B=b;this.b=c;this.C=d;zd(this)};
xd.prototype.ua=function(){if(this.wa){if(this.C){var a=this.C,b=this.id,c=this.H,d=this.w,e=this.wa,f=[],h;for(h in e){var g=e[h];"number"==typeof g&&(e[h]=g={o:g});var k=g.o,l=g.a;if(void 0!==k){var n=f,k=[k>>>0,h],q=ia(n,k,a.Cb);0>q&&n.splice(-(q+1),0,k)}l&&(g.a=l.replace(/''/g,'"'))}a.I.push({lc:b,A:c,ec:d,wa:e,Bb:f})}delete this.wa}return!0};xd.prototype.ta=function(){return!0};
function yd(a,b,c,d){if(d)a.ka("Unable to load system ROM (error "+d+": "+b+")");else{Ya(a.Eb,b,c);if("["==c.charAt(0)||"{"==c.charAt(0))try{var e=eval("("+c+")"),f=e.bytes,h=e.data;if(f)a.s=f;else if(h)for(a.s=Array(4*h.length),d=c=0;c<h.length;c++)a.s[d++]=h[c]&255,a.s[d++]=h[c]>>8&255,a.s[d++]=h[c]>>16&255,a.s[d++]=h[c]>>24&255;else a.s=e;a.wa=e.symbols;if(!a.s.length){t("Empty ROM: "+b);return}if(1==a.s.length){t(a.s[0]);return}}catch(g){a.ka("ROM data error: "+g.message);return}else for(b=c.replace(/\n/gm,
" ").replace(/ +$/,"").split(" "),a.s=Array(b.length),e=0;e<b.length;e++)a.s[e]=aa(b[e],16);zd(a)}}
function zd(a){if(!lb(a))if(!a.G)B(a);else if(a.s&&a.B){if(a.s.length!=a.w)mb(a,"ROM size (0x"+p(a.s.length)+") does not match specified size ("+("0x"+p(a.w))+")");else{var b;b=a.H;if(ub(a.B,b,a.w,Qb)){for(var c=0;c<a.s.length;c++){var d=a.B,e=b+c;d.B[(e&d.G)>>>d.X].Ya(e&d.s,a.s[c]&255,e)}b=!0}else b=!1;if(b){b=[];"number"==typeof a.D?b.push(a.D):null!=a.D&&a.D.length&&(b=a.D);for(c=0;c<b.length;c++){for(var f=a,d=b[c],e=f.B,h=f.w,g=[],k=f.H>>>e.X;0<h&&k<e.B.length;)g.push(e.B[k++]),h-=e.ia;e=f.B;
f=f.w;h=0;for(d>>>=e.X;0<f&&d<e.B.length;){k=g[h++];if(!k)break;e.B[d++]=k;f-=e.ia}}delete a.s}}B(a)}}Ja(function(){for(var a=z(document,"pc8080","rom"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new xd(d);db(d,c)}});function Ad(a){v.call(this,"RAM",a,Ad);this.D=a.addr;this.w=a.size;this.s=!1}x(Ad);m=Ad.prototype;m.za=function(a,b,c,d){this.B=b;this.b=c;this.C=d;B(this)};m.ua=function(a,b){b||this.reset();return!0};m.ta=function(a){return a?this.save():!0};
m.reset=function(){!this.s&&this.w&&ub(this.B,this.D,this.w,1)&&(this.s=!0,this.status(Math.floor(this.w/1024)+"Kb allocated"));this.s||t("No RAM allocated")};m.save=function(){return null};m.restore=function(){return!0};Ja(function(){for(var a=z(document,"pc8080","ram"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new Ad(d);db(d,c)}});function Bd(a){v.call(this,"Keyboard",a,Bd,65536);B(this)}x(Bd);
Ja(function(){for(var a=z(document,"pc8080","keyboard"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new Bd(d);db(d,c)}});function Cd(a){v.call(this,"Video",a,Cd,262144);this.Xb=a.interruptRate;this.xa=a.refreshRate||60;B(this)}x(Cd);Cd.prototype.za=function(a,b,c,d){this.s=a;this.B=b;this.b=c;this.C=d};
Ja(function(){for(var a=z(document,"pc8080","video"),b=0;b<a.length;b++){var c=a[b],d=y(c),e=document.createElement("canvas");if(void 0===e||!e.getContext){c.innerHTML="<br/>Missing &lt;canvas&gt; support. Please try a newer web browser.";break}e.setAttribute("class","pcjs-canvas");e.setAttribute("width",d.screenWidth);e.setAttribute("height",d.screenHeight);e.style.backgroundColor=d.screenColor;e.style.height="auto";0<=oa().indexOf("MSIE")&&(c.onresize=function(a,b,c,d){return function(){b.style.height=
(a.clientWidth*d/c|0)+"px"}}(c,e,d.screenWidth,d.screenHeight),c.onresize());var f=+(d.aspect||Sa.aspect);f&&.3<=f&&3.33>=f&&(Ia("onresize",function(a,b,c){return function(){b.style.height=(a.clientWidth/c|0)+"px"}}(c,e,f)),window.onresize());c.appendChild(e);f=document.createElement("textarea");Ba("iOS")&&(f.setAttribute("autocapitalize","off"),f.setAttribute("autocorrect","off"));c.appendChild(f);e.getContext("2d");d=new Cd(d);db(d,c)}});
function Dd(a){v.call(this,"Debugger",a,Dd);this.ea=this.Ka=this.T=0;this.Y=V();this.Db=V();this.G=-1;this.D=[];this.qa=!1;this.na=V();this.I=[];this.pa={};this.w=this.Z=this.H=[];Ed(this);this.Aa=0;Fd(this);this.Za=[];Gd(this,a.messages);this.ab=a.commands;var b=this;window?void 0===window.$&&(window.$=function(a){return pc(b,a)}):void 0===global.$&&(global.$=function(a){return pc(b,a)})}x(Dd);
var Hd={"?":"help/print","a [#]":"assemble","b [#]":"breakpoint",c:"clear output","d [#]":"dump memory","e [#]":"edit memory",f:"frequencies","g [#]":"go [to #]",h:"halt","i [#]":"input port #","if":"eval expression",k:"stack trace",ln:"list nearest symbol(s)",m:"messages","o [#]":"output port #",p:"step over",print:"print expression",r:"dump/set registers",reset:"reset machine","t [#]":"trace","u [#]":"unassemble",x:"execution options",v:"print version","var":"assign variable"},Id="NONE ACI ADC ADD ADI ANA ANI CALL CC CM CNC CNZ CP CPE CPO CZ CMA CMC CMP CPI DAA DAD DCR DCX DI EI HLT IN INR INX JMP JC JM JNC JNZ JP JPE JPO JZ LDA LDAX LHLD LXI MOV MVI NOP ORA ORI OUT PCHL POP PUSH RAL RAR RET RC RM RNC RNZ RP RPE RPO RZ RLC RRC RST SBB SBI SHLD SPHL STA STAX STC SUB SUI XCHG XRA XRI XTHL".split(" "),
Jd="B C D E H L M A F BC DE HL PSW SP PC".split(" "),Kd=[[45],[42,2323,32],[71,2387],[29,2323],[28,17],[22,17],[44,17,32],[63],[45,32768],[21,2835,6419],[40,2387],[23,2323],[28,273],[22,273],[44,273,32],[64],[45,32768],[42,2579,32],[71,2643],[29,2579],[28,529],[22,529],[44,529,32],[52],[45,32768],[21,2835,6675],[40,2643],[23,2579],[28,785],[22,785],[44,785,32],[53],[45,32768],[42,2835,32],[68,99],[29,2835],[28,1041],[22,1041],[44,1041,32],[20],[45,32768],[21,2835,6931],[41,99],[23,2835],[28,1297],
[22,1297],[44,1297,32],[16],[45,32768],[42,3347,32],[70,99],[29,3347],[28,1617],[22,1617],[44,1617,32],[72],[45,32768],[21,2835,7443],[39,99],[23,3347],[28,1809],[22,1809],[44,1809,32],[17],[43,17,17],[43,17,273],[43,17,529],[43,17,785],[43,17,1041],[43,17,1297],[43,17,1617],[43,17,1809],[43,273,17],[43,273,273],[43,273,529],[43,273,785],[43,273,1041],[43,273,1297],[43,273,1617],[43,273,1809],[43,529,17],[43,529,273],[43,529,529],[43,529,785],[43,529,1041],[43,529,1297],[43,529,1617],[43,529,1809],
[43,785,17],[43,785,273],[43,785,529],[43,785,785],[43,785,1041],[43,785,1297],[43,785,1617],[43,785,1809],[43,1041,17],[43,1041,273],[43,1041,529],[43,1041,785],[43,1041,1041],[43,1041,1297],[43,1041,1617],[43,1041,1809],[43,1297,17],[43,1297,273],[43,1297,529],[43,1297,785],[43,1297,1041],[43,1297,1297],[43,1297,1617],[43,1297,1809],[43,1617,17],[43,1617,273],[43,1617,529],[43,1617,785],[43,1617,1041],[43,1617,1297],[43,1617,1617],[43,1617,1809],[43,1809,17],[43,1809,273],[43,1809,529],[43,1809,
785],[43,1809,1041],[43,1809,1297],[43,1809,1617],[43,1809,1809],[3,17],[3,273],[3,529],[3,785],[3,1041],[3,1297],[3,1617],[3,1809],[2,17],[2,273],[2,529],[2,785],[2,1041],[2,1297],[2,1617],[2,1809],[73,17],[73,273],[73,529],[73,785],[73,1041],[73,1297],[73,1617],[73,1809],[66,17],[66,273],[66,529],[66,785],[66,1041],[66,1297],[66,1617],[66,1809],[5,17],[5,273],[5,529],[5,785],[5,1041],[5,1297],[5,1617],[5,1809],[76,17],[76,273],[76,529],[76,785],[76,1041],[76,1297],[76,1617],[76,1809],[46,17],[46,
273],[46,529],[46,785],[46,1041],[46,1297],[46,1617],[46,1809],[18,17],[18,273],[18,529],[18,785],[18,1041],[18,1297],[18,1617],[18,1809],[58],[50,2323],[34,35],[30,35],[11,35],[51,2323],[4,33],[65],[62],[54],[38,35],[30,32803],[15,35],[7,35],[1,33],[65],[57],[50,2579],[33,35],[48,33],[10,35],[51,2579],[74,33],[65],[55],[54,32768],[31,35],[27,33],[8,35],[7,32803],[67,33],[65],[61],[50,2835],[37,35],[78,3411,2835],[14,35],[51,2835],[6,33],[65],[60],[49,3603,2835],[36,35],[75,2835,2579],[13,35],[7,
32803],[77,33],[65],[59],[50,3091],[35,35],[24],[12,35],[51,3091],[47,33],[65],[56],[69,3347,2835],[32,35],[25],[9,35],[7,32803],[19,33],[65]],Ld={cpu:1,bus:64,mem:128,port:256,chipset:32768,keyboard:65536,key:131072,video:262144,fdc:524288,disk:2097152,serial:8388608,speaker:33554432,computer:67108864,log:536870912,warn:1073741824,halt:-2147483648};m=Dd.prototype;
m.za=function(a,b,c,d){this.B=b;this.b=c;this.s=a;(a=mc(a,"messages"))&&Gd(this,a);this.zb=Kd;Md(this,function(a){a:{var b=d.b.ja,c=a[0],g=a=0,k=b.length;if(c){a=X(Y(d,c));if(-1===a){d.g("invalid address: "+c);break a}g=a>>>d.b.X;k=1}d.g("blockid physical blockaddr used size type");d.g("-------- --------- ---------- ------ ------ ----");for(var c=-1,l=0;k--;){var n=b[g];n.type==c?l++||d.g("..."):(c=n.type,l=Vb[c],n&&d.g(p(n.id)+" %"+p(g<<d.b.X)+" %%"+p(n.A)+" "+r(n.kb)+" "+r(n.size)+
" "+l),c!=Pb&&(c=-1),l=0);a+=d.b.ia;g++}}});B(this)};
m.ma=function(a,b,c){var d=this;switch(b){case "debugInput":return this.va=this.R[b]=c,c.onkeydown=function(a){var b;if(13==a.keyCode)b=c.value,c.value="",pc(d,b,!0);else if(27==a.keyCode)c.value=b="";else if(38==a.keyCode?d.G<d.D.length-1&&(b=d.D[++d.G]):40==a.keyCode&&(0<d.G?b=d.D[--d.G]:(b="",d.G=-1)),null!=b){var h=b.length;c.value=b;c.setSelectionRange(h,h)}null!=b&&a.preventDefault&&a.preventDefault()},!0;case "debugEnter":return this.R[b]=c,Da(c,function(){if(d.va){var a=d.va.value;d.va.value=
"";pc(d,a,!0);return!0}return!1}),!0;case "step":return this.R[b]=c,Da(c,function(a){var b=!1;kb(d,!0)||(jb(d,!0),b=d.Wa(a?1:0),jb(d,!1));return b}),!0}return!1};m.jb=function(){this.va&&this.va.focus()};function X(a){a=a&&a.A;null==a&&(a=-1);return a}m.U=function(a,b){var c=255,d=X(a);-1!==d&&(c=wb(this.B,d),b&&Nd(a,b));return c};m.lb=function(a,b){var c=65535,d=X(a);if(-1!==d){var c=this.B,e=d&c.s,f=(d&c.G)>>>c.X,c=e!=c.s?c.B[f].wb(e,d):c.B[f++].ib(e,d)|c.B[f&c.W].ib(0,d+1)<<8;b&&Nd(a,b)}return c};
m.yb=function(a,b,c){var d=X(a);if(-1!==d){var e=this.B;e.B[(d&e.G)>>>e.X].Ya(d&e.s,b&255,d);c&&Nd(a,c);D(this.b,!0)}};m.Sb=function(a,b,c){var d=X(a);if(-1!==d){var e=this.B,f=d&e.s,h=(d&e.G)>>>e.X;f!=e.s?e.B[h].xb(f,b&65535,d):(e.B[h++].Ya(f,b&255,d),e.B[h&e.W].Ya(0,b>>8&255,d+1));c&&Nd(a,c);D(this.b,!0)}};function V(a){return{A:a||0,sa:!1}}function Od(a){return[a.A,a.sa]}function Pd(a){return{A:a[0],sa:a[1]}}
function Y(a,b,c){var d;c=(c?a.Y:a.Db).A;if(void 0!==b){d=b=Qd(a,b);var e;if(d.match(/^[a-z_][a-z0-9_]*$/i))for(d=d.toUpperCase(),c=0;c<a.I.length;c++){var f=a.I[c].wa[d];if(void 0!==f){d=f.o;void 0!==d&&(e=V(d));break}}if(d=e)return d;c=Rd(a,b,void 0)}null!=c&&(d=V(c));return d}function Sd(a,b,c){c&&(c=c.match(/(['"])(.*?)\1/))&&(b.Tb=Td(a,b.Qb=c[2]))}function Nd(a,b){null!=a.A&&(a.A+=b||1)}function Z(a){return p(a,4)}
function Ud(a,b,c){var d="";for(c=c||256;d.length<c;){var e=a.U(b,1);if(!e||36==e||127<=e)break;d+=32<=e?String.fromCharCode(e):"."}return d}function Gd(a,b){a.C=a;a.fa=a.Ub=1073741824;a.Ba=null;var c=Td(a,b.replace("keys","key").replace("kbd","keyboard"),!1,"|");if(c.length)for(var d in Ld)0<=la(c,d)&&(a.fa|=Ld[d],a.g(d+" messages enabled"))}function Md(a,b){for(var c in Ld)if(64==Ld[c]){a.Za[c]=b;break}}
function Vd(a,b){var c;a=a.toUpperCase();null==b?c=la(Jd,a):(c=la(Jd,a.substr(b,3)),0>c&&(c=la(Jd,a.substr(b,2))));return c}function Wd(a,b){var c=0,d=Xd(a,b);if(void 0!==d)switch(b){case 7:case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 8:c=2;break;case 9:case 10:case 11:case 12:case 13:case 14:c=4}return c?p(d,c):"??"}
function Xd(a,b){var c;if(0<=b){var d=a.b;switch(b){case 7:c=d.j;break;case 8:c=Bc(d);break;case 0:c=d.K;break;case 1:c=d.N;break;case 9:c=Cc(d);break;case 2:c=d.L;break;case 3:c=d.O;break;case 10:c=Ec(d);break;case 4:c=d.M;break;case 5:c=d.P;break;case 11:c=I(d);break;case 6:c=d.U(I(d));break;case 12:c=d.j<<8|Bc(d)&255;break;case 13:c=d.aa;break;case 14:c=d.J}}return c}
function Yd(a,b){b=Qd(a,b);for(var c=0,d,e;0<=(c=b.indexOf("@",c));)e=Vd(b,c+1),0<=e&&(b=b.substr(0,c)+Wd(a,e)+b.substr(c+1+Jd[e].length)),c++;for(c=0;0<=(c=b.indexOf("#",c));)e=b.substr(c+1,2),d=aa(e,16),null!=d&&32<=d&&128>d?(d=e+" '"+String.fromCharCode(d)+"'",b=b.replace("#"+e,d),c+=d.length):c++;for(c=0;0<=(c=b.indexOf("$",c));)e=b.substr(c+1,9),(d=Y(a,e))?(d=e+' "'+Ud(a,d)+'"',b=b.replace("$"+e,d),c+=d.length):c++;for(c=0;0<=(c=b.indexOf("^",c));)e=b.substr(c+1,9),(d=Y(a,e))?(Nd(d),d=e+' "'+
Ud(a,d,11)+'"',b=b.replace("^"+e,d),c+=d.length):c++;return b}m.message=function(a,b){b&&(a+=" at "+Z(V(this.b.J).A));if(!this.Ba||a!=this.Ba)if(this.Ba=a,this.fa&-2147483648&&(this.da(),a+=" (cpu halted)"),this.g(a),this.b){var c=this.b;c.i.Ua=0;c.D-=c.b;c.b=0;D(c)}};function hb(a,b,c,d,e,f,h,g){g|=256;null!=e&&(a.fa&g)!=g||a.message(b.$a+"."+(null!=d?"outPort":"inPort")+"("+r(c)+","+(f?f:"unknown")+(null!=d?",0x"+p(d,2):"")+")"+(null!=h?": 0x"+p(h,2):"")+(null!=e?" at "+Z(e):""))}
function Fd(a){var b;if(od(a)){if(!a.W||!a.W.length){a.W=Array(1E3);for(b=0;b<a.W.length;b++)a.W[b]=V();a.ra=0;a.g("instruction history buffer allocated")}if(!a.S||!a.S.length)for(a.S=Array(256),b=0;b<a.S.length;b++)a.S[b]=[b,0]}else a.W&&a.W.length&&a.g("instruction history buffer freed"),a.ra=0,a.W=[],a.S=[]}m.Ja=function(a){if(!Zd(this))return!1;this.b.Ja(a);return!0};
m.Wa=function(a,b,c){if(!Zd(this))return!1;this.T=0;a||od(this)&&pd(this,this.b.J,0);try{var d=this.b.Wa(a);0<d&&(this.T+=d,uc(this.b,d,!0),rc(this.b,d),this.ea++)}catch(e){"number"!=typeof e&&(this.T=0,mb(this.b,e.stack||e.message))}!1!==c&&D(this.b);this.oa(b||!1);return 0<this.T};m.da=function(a){this.b&&this.b.da(a)};m.oa=function(a){void 0===a&&(a=!0);this.Y=V(this.b.J);a&&1!=this.ba?$d(this):ae(this)};
function Zd(a){var b;if(b=a.b&&lb(a.b))b=a.b,b.u.ga?b=!0:(b.g(b.toString()+" not powered"),b=!1);b&&!kb(a.b)?(a=a.b,a.u.Na?(a.g(a.toString()+" error"),a=!0):a=!1,a=!a):a=!1;return a}m.ua=function(a,b){return!b&&(this.reset(!0),a&&this.restore&&!this.restore(a))?!1:!0};m.ta=function(a,b){b&&this.g(a?"suspending":"shutting down");return a?this.save():!0};m.reset=function(a){Fd(this);this.ea=this.Ka=0;this.Ba=null;this.T=0;this.Y=V(this.b.J);this.u.ha=!1;be(this);a||this.oa()};
m.save=function(){var a=new G(this);H(a,0,Od(this.Y));H(a,1,Od(this.na));H(a,2,[this.D,this.qa,this.fa]);H(a,3,this.I);return a.data()};m.restore=function(a){var b=0;void 0!==a[2]&&(this.Y=Pd(a[b++]),this.na=Pd(a[b++]),this.D=a[b][0],"string"==typeof this.D&&(this.D=[this.D]),this.qa=a[b][1],this.fa|=a[b][2]);a[3]&&(this.I=a[3]);return!0};m.start=function(a,b){this.ba||this.g("running");this.u.ha=!0;this.Yb=a;this.Zb=b};
m.stop=function(a,b){if(this.u.ha){this.u.ha=!1;this.T=b-this.Zb;if(!this.ba){var c="stopped";if(this.T){var d=a-this.Yb,e=0<d?Math.round(1E3*this.T/d):0,c=c+" (";od(this)&&(c+=this.ea+" opcodes, ",this.Ka-=this.ea,this.ea=0);c+=this.T+" cycles, "+d+" ms, "+e+" hz)"}else ib(this,-2147483648)&&(c+=" (use the 't' command to execute blocked faults)");this.g(c)}this.oa(!0);this.jb();be(this,this.b.J)}};function od(a){return 1<a.w.length||!!a.Aa}
function pd(a,b,c){var d=a.b;if(0<c&&(a.Aa&&!--a.Aa||Zb(a,b,1,a.w)))return!0;0<=c&&a.S.length&&(a.ea++,b=wb(a.B,b),null!=b&&(a.S[b][1]++,b=a.W[a.ra],b.A=d.J,b.sa=!1,++a.ra==a.W.length&&(a.ra=0)));return!1}function Hb(a,b,c){a.g("break on input from port "+r(b)+": "+p(c));a.da(!0)}function Kb(a,b,c){a.g("break on output to port "+r(b)+": "+p(c));a.da(!0)}
function Ed(a){var b,c;a.w=["bp"];if(void 0!==a.Z)for(b=1;b<a.Z.length;b++){c=a.Z[b];var d=a.b;$b(d.ja[X(c)>>>d.X],!1)}a.Z=["br"];if(void 0!==a.H)for(b=1;b<a.H.length;b++)c=a.H[b],d=a.b,$b(d.ja[X(c)>>>d.X],!0);a.H=["bw"];a.Fb=0}m.Ca=function(a,b,c){var d=!0;c||ce(this,a,b,!1,!0);if(a!=this.w){var e=X(b);if(-1===e)this.g("invalid address: "+Z(b.A)),d=!1;else{var f=this.b;f.ja[e>>>f.X].Ca(e&f.G,a==this.H)}}d&&(a.push(b),c?b.sa=!0:(de(this,a,a.length-1,"set"),Fd(this)));return d};
function ce(a,b,c,d,e){var f=!1;c=X(c);for(var h=1;h<b.length;h++){var g=b[h];if(c==X(g)&&(!d||g.sa)){f=!0;g.sa||e||de(a,b,h,"cleared");b.splice(h,1);b!=a.w&&(d=a.b,$b(d.ja[c>>>d.X],b==a.H));g.sa||Fd(a);break}}return f}function ee(a,b){for(var c=1;c<b.length;c++)de(a,b,c);return b.length-1}function de(a,b,c,d){c=b[c];a.g(b[0]+" "+Z(c.A)+(d?" "+d:c.Qb?' "'+c.Qb+'"':""))}
function be(a,b){if(void 0!==b)Zb(a,b,1,a.w,!0),a.ba=0;else for(var c=1;c<a.w.length;c++){var d=a.w[c];if(d.sa){if(!ce(a,a.w,d,!0))break;c=0}}}
function Zb(a,b,c,d,e){var f=!1;if(!a.Fb++)for(var h=1;!f&&h<d.length;h++){var g=d[h];if(!e||g.sa)for(var k=X(g),l=0;l<c;l++)if(b+l==k){var n,f=!0;g.sa&&(ce(a,d,g,!0),e=!0);if(n=g.Tb){for(var f=!1,q=0;q<n.length;q++)if(!fe(a,n[q],!0)){if(n[q].indexOf("if")){f=!0;break}for(var u=q+1;u<n.length&&n[u].indexOf("else");u++)q++;if(u==n.length){f=!0;break}}a.b.u.ha||(f=!0)}if(f){e||de(a,d,h,"hit");break}}}a.Fb--;return f}
function ge(a,b,c,d){for(var e=V(b.A),f=a.U(b,1),h=a.zb[f],f="",g=Id[h[0]],k=h.length-1,l=0,n,q=1;q<=k;q++){var u="";n=h[q];if(void 0!==n){var W=n&15;W?l=W:n|=l;n&61440||(n|=1==q?8192:4096);W=n&240;if(W&32){var u=a,W=n,R=b,qa=" ";switch(W&15){case 1:qa=p(u.U(R,1),2);break;case 2:qa=p(u.U(R,1)<<24>>24,4);break;case 3:qa=p(u.lb(R,2),4);break;default:qa="imm("+r(W)+")"}W&64&&(qa="["+qa+"]");u=qa}else W&16&&(u=(n&3840)>>8,u=6==u?"[HL]":Jd[u]);if(!u||!u.length){f="INVALID";break}0<f.length&&(f+=",");f+=
u||"???"}}h="";k=Z(e.A)+" ";if(-1!==e.A&&-1!==b.A){do if(h+=p(a.U(e,1),2),null==e.A)break;while(e.A!=b.A)}k+=ga(h,10);k=k+(n&32768?"*":" ")+ga(g,7);f&&(k+=" "+f);c&&(k=ga(k,40)+";"+c,k=a.b.u.Ma?k+("cycles="+sc(a.b).toString()+" cs="+p(a.b.i.bb)):k+(null!=d?"="+d.toString():""));return k}
function he(a,b){var c;switch(b){case "I":c=a.b.la&512;break;case "S":c=Jc(a.b);break;case "Z":c=Ic(a.b);break;case "A":c=Hc(a.b);break;case "P":c=Gc(a.b);break;case "C":c=K(a.b);break;default:c=0}return b+(c?"1":"0")+" "}function ie(a,b){return Jd[b]+"="+Wd(a,b)+" "}function je(a){return ie(a,7)+ie(a,8)+ie(a,0)+ie(a,1)+ie(a,2)+ie(a,3)+ie(a,4)+ie(a,5)+ie(a,13)+he(a,"I")+he(a,"S")+he(a,"Z")+he(a,"A")+he(a,"P")+he(a,"C")}
var Je={"||":0,"&&":1,"|":2,"^":3,"&":4,"!=":5,"==":5,">=":6,">":6,"<=":6,"<":6,">>>":7,">>":7,"<<":7,"-":8,"+":8,"%":9,"/":9,"*":9};
function Ke(a,b,c){for(c=c||-1;c--&&b.length;){var d=b.pop();if(2>a.length)return!1;var e=a.pop(),f=a.pop();switch(d){case "*":d=f*e;break;case "/":if(!e)return!1;d=f/e;break;case "%":if(!e)return!1;d=f%e;break;case "+":d=f+e;break;case "-":d=f-e;break;case "<<":d=f<<e;break;case ">>":d=f>>e;break;case ">>>":d=f>>>e;break;case "<":d=f<e?1:0;break;case "<=":d=f<=e?1:0;break;case ">":d=f>e?1:0;break;case ">=":d=f>=e?1:0;break;case "==":d=f==e?1:0;break;case "!=":d=f!=e?1:0;break;case "&":d=f&e;break;
case "^":d=f^e;break;case "|":d=f|e;break;case "&&":d=f&&e?1:0;break;case "||":d=f||e?1:0;break;default:return!1}a.push(d|0)}return!0}
function Kd(a,b,c){var d;if(b){b=Jd(a,b);for(var e=0,f=!1,h=b,g=[],k=[],l=b.split(/(\|\||&&|\||^|&|!=|==|>=|>>>|>>|>|<=|<<|<|-|\+|%|\/|\*)/);e<l.length;){var n=l[e++],q=n.length,n=ha(n);if(!n){f=!0;break}n=ee(a,n,null,!1===c);if(void 0===n){f=!0;c=!1;break}g.push(n);if(e==l.length)break;var n=l[e++],v=n.length;k.length&&ce[n]<ce[k[k.length-1]]&&de(g,k,1);k.push(n);b=b.substr(q+v)}de(g,k)&&1==g.length||(f=!0);f?c&&a.g("error parsing '"+h+"' at character "+(h.length-b.length)):(d=g.pop(),c&&Ee(a,null,
d))}return d}function Jd(a,b){for(var c;(c=b.match(/\{(.*?)}/))&&!(0<=c[1].indexOf("{"));){var d=Kd(a,c[1]);b=b.replace("{"+c[1]+"}",null!=d?p(d):"undefined")}for(;(c=b.match(/\[(.*?)]/))&&!(0<=c[1].indexOf("["));)d=Z(a,c[1]),b=b.replace("["+c[1]+"]",d?p(a.jb(d,0),4):"undefined");for(c=b;d=c.match(/\$([a-z]+)/i);){var e=null;switch(d[1].toLowerCase()){case "ops":e=a.ea-a.Ha}if(null==e)break;c=c.replace(d[0],e.toString())}return c}
function ee(a,b,c,d){var e;void 0!==b?(e=Od(b),0<=e?e=Qd(a,e):(e=a.na[b],void 0===e&&(e=aa(b))),void 0!==e||d||a.g("invalid "+(c?c:"value")+": "+b)):d||a.g("missing "+(c||"value"));return e}
function Ee(a,b,c){var d,e=!1;if(void 0!==c){e=!0;d=c;var f,h="";if(!f||4<f)f=4;for(var g=0;g<f;g++){h&&(h=","+h);var k=d&255,l=8,n="";void 0===l?l=32:32<l&&(l=32);if(null==k||isNaN(k))for(;0<l--;)n="?"+n;else for(;0<l--;)n=(k&1?"1":"0")+n,k>>=1;h=n+"b"+h;d>>=8}d="0x"+p(c)+" "+c+". ("+h+")"}a.g((null!=b?b+": ":"")+d);return e}function Fe(a,b){if(b)return Ee(a,b,a.na[b]);var c=0;for(b in a.na)Ee(a,b,a.na[b]),c++;return 0<c}wd.prototype.yb=function(a,b){return a[0]>b[0]?1:a[0]<b[0]?-1:0};
function Ge(a,b,c){var d=[],e=Y(b)>>>0;for(b=0;b<a.M.length;b++){var f=a.M[b],h=f.w>>>0,g=f.Zb;if(e>=h&&e<h+g){e=ia(f.zb,[e-h],a.yb);0<=e?He(a,b,e,d):c&&(e=~e,He(a,b,e-1,d),He(a,b,e,d));break}}return d}function He(a,b,c,d){var e={},f=a.M[b].zb,h=0,g=null;0<=c&&c<f.length&&(h=f[c][0],g=f[c][1]);g&&(e=a.M[b].ta[g],g="."==g.charAt(0)?null:e.l||g);d.push(g);d.push(h);d.push(e.a);d.push(e.c)}
function Ie(a,b){if("?"==b)a.g("frequency commands:"),a.g("\tclear\tclear all frequency counts");else{var c,d=0;if(a.S)if("clear"==b){for(c=0;c<a.S.length;c++)a.S[c]=[c,0];a.g("frequency data cleared");d++}else if(void 0!==b)a.g("unknown frequency command: "+b),d++;else{var e=a.S.slice();e.sort(function(a,b){return b[1]-a[1]});for(c=0;c<e.length;c++){var f=e[c][0],h=e[c][1];h&&(a.g((Bd[a.kb[f][0]]+" ").substr(0,5)+" ("+("0x"+p(f,2))+"): "+h+" times"),d++)}}d||a.g("no frequency data available")}}
function Je(a,b){var c=b.match(/^\s*([A-Z_]?[A-Z0-9_]*)\s*(=?)\s*(.*)$/i);if(c){if(!c[1])return Fe(a)||a.g("no variables"),!0;if(!c[2])return Fe(a,c[1]);if(!c[3])return delete a.na[c[1]],!0;var d=Kd(a,c[3]);return void 0!==d?(a.na[c[1]]=d,!0):!1}a.g("invalid assignment:"+b);return!1}
function Ke(a,b,c){var d=null;if(b=Z(a,b,!0)){var e=Ge(a,b,!0);if(e.length){var f,h;e[0]&&(h="",(f=b.w-e[1])&&(h=" + "+r(f)),f=e[0]+" ("+p(e[1],4)+")"+h,c&&a.g(f),d=f);4<e.length&&e[4]&&(h="",(f=e[5]-b.w)&&(h=" - "+r(f)),f=e[4]+" ("+p(e[5],4)+")"+h,c&&a.g(f),d||(d=f))}else c&&a.g("no symbols")}return d}
function Td(a,b){var c;if(b&&"?"==b[1])a.g("register commands:"),a.g("\tr\tdump registers"),a.g("\trx [#]\tset flag or register x to [#]");else{var d=a.b;null==c&&(c=!0);if(null!=b&&1<b.length){var e=b[1],f=null,h=e.indexOf("=");if(0<h)f=e.substr(h+1),e=e.substr(0,h);else if(2<b.length)f=b[2];else{a.g("missing value for "+b[1]);return}var h=!1,g=Kd(a,f);if(void 0!==g){var h=!0,k=e.toUpperCase();"E"==k.charAt(0)&&(k=null);switch(k){case "A":d.i=g&255;break;case "B":d.I=g&255;break;case "BC":d.I=g>>
8&255;case "C":d.O=g&255;break;case "D":d.J=g&255;break;case "DE":d.J=g>>8&255;case "E":d.P=g&255;break;case "H":d.K=g&255;break;case "HL":d.K=g>>8&255;case "L":d.R=g&255;break;case "SP":d.Z=g&65535;break;case "PC":E(d,g);a.W=X(d.L);break;case "PS":xc(d,g);break;case "C":d.D=g?d.D|256:d.D&255;break;case "P":g?N(d)||(d.T^=1):N(d)&&(d.T^=1);break;case "A":d.ba=g?~d.T&16|d.ba&-17:d.T&16|d.ba&-17;break;case "Z":d.D=g?d.D&-256:d.D|255;break;case "S":g?Fc(d)||(d.T^=192):Fc(d)&&(d.T^=192);break;case "I":d.oa=
g?d.oa|512:d.oa&-513;break;default:a.g("unknown register: "+e);return}}if(!h){a.g("invalid value: "+f);return}D(d);a.g("updated registers:")}a.g(be(a,7)+be(a,8)+be(a,0)+be(a,1)+be(a,2)+be(a,3)+be(a,4)+be(a,5)+be(a,13)+ae(a,"I")+ae(a,"S")+ae(a,"Z")+ae(a,"A")+ae(a,"P")+ae(a,"C"));c&&(a.W=X(d.L),Ud(a,p(a.W.w,4)))}}function Le(a,b){b=ha(b);var c=b.match(/^(['"])(.*?)\1$/);c?a.g(Rd(a,c[2])):Kd(a,b,!0)}
function Me(a,b,c){var d="t"!=b;c=ee(a,c,null,!0)||1;var e=1==c?0:1;"tc"==b&&(e=c,c=1);Ca(c,function(){return gb(a,!0)&&a.Ua(e,d,!1)},function(){D(a.b);gb(a,!1)})}
function Ud(a,b,c,d){if(b=Z(a,b,!0)){void 0===d&&(d=1);var e=256;if(void 0!==c){d=Z(a,c,!0);if(!d||d.w<b.w)return;e=d.w-b.w;if(256<e){a.g("range too large");return}d=-1}c=0;for(var f;0<e&&d--;){f=hb(a,!1)||a.aa?a.U:null;var h=null!=f?"cycles":null,g=Ge(a,b),k=b.w;if(g[0]&&d&&(!c&&d||0>g[0].indexOf("+"))){var l=g[0]+":";g[2]&&(l+=" "+g[2]);a.g(l)}g[3]&&(h=g[3],f=null);f=$d(a,b,h,f);a.g(f);a.W=b;e-=b.w-k;c++}}}
function Md(a,b,c,d){if(c)if(b){0>a.G&&a.F.length&&(a.G=0);if(0>a.G||b!=a.F[a.G])a.F.splice(0,0,b),a.G=0;a.G--}else b=a.F[a.G+1];a=[];if(b){b=b.toLowerCase().replace(/""/g,"'");c=0;var e=null;d=d||";";for(var f=0;f<=b.length;f++){var h=b.charAt(f);if('"'==h||"'"==h)e?h==e&&(e=null):e=h;else if(h==d&&!e||!h)a.push(ha(b.substring(c,f))),c=f+1}}return a}
function Zd(a,b,c){var d=!0;try{b.length&&"end"!=b?c||a.g(">> "+b):(a.pa&&(a.g("ended assemble at "+p(a.ia.w,4)),a.W=a.ia,a.pa=!1),b="");var e=b.charAt(0);if('"'==e||"'"==e)return!0;a.za=null;if(ib(a)&&0<b.length){a.pa&&(b="a "+p(a.ia.w,4)+" "+b);var f=b.replace(/ +/g," ").split(" ");if(f&&f.length)for(var h=f[0],g=h.charAt(0),k=1;k<h.length;k++){var l=h.charAt(k);if("?"==g||"r"==g||"a">l||"z"<l){f[0]=h.substr(k);f.unshift(h.substr(0,k));break}}switch(f[0].charAt(0)){case "a":var n=Z(a,f[1],!0);if(n)if(a.ia=
n,void 0===f[2])a.g("begin assemble at "+p(n.w,4)),a.pa=!0,D(a.b);else{var q;a.g("not supported yet");q=[];if(q.length){for(var v=0;v<q.length;v++)a.wb(n,q[v],1);a.g($d(a,a.ia))}}break;case "b":a:{var R=f[0],H=f[1],hf=b;if("?"==H)a.g("breakpoint commands:"),a.g("\tbi [p]\ttoggle break on input port [p]"),a.g("\tbo [p]\ttoggle break on output port [p]"),a.g("\tbp [a]\tset exec breakpoint at addr [a]"),a.g("\tbr [a]\tset read breakpoint at addr [a]"),a.g("\tbw [a]\tset write breakpoint at addr [a]"),
a.g("\tbc [a]\tclear breakpoint at addr [a]"),a.g("\tbl\tlist all breakpoints"),a.g("\tbn [n]\tbreak after [n] instruction(s)");else{var oa=R.charAt(1);if("l"==oa){var Xa=0,Xa=Xa+Yd(a,a.A),Xa=Xa+Yd(a,a.Y);(Xa+=Yd(a,a.H))||a.g("no breakpoints")}else if("n"==oa)a.ya=ee(a,H),a.g("break after "+a.ya+" instruction(s)");else if(void 0===H)a.g("missing breakpoint address");else{var F=X();if("*"!=H&&(F=Z(a,H,!0),!F))break a;H=r(F.w);"c"==oa?null==F.w?(xd(a),a.g("all breakpoints cleared")):Wd(a,a.A,F)||Wd(a,
a.Y,F)||Wd(a,a.H,F)||a.g("breakpoint missing: "+p(F.w,4)):"i"==oa?a.g("breakpoint "+(Cb(a.B,F.w)?"enabled":"cleared")+": port "+H+" (input)"):"o"==oa?a.g("breakpoint "+(Gb(a.B,F.w)?"enabled":"cleared")+": port "+H+" (output)"):null!=F.w&&(Ld(a,F,hf),"p"==oa?a.Aa(a.A,F):"r"==oa?a.Aa(a.Y,F):"w"==oa?a.Aa(a.H,F):a.g("unknown breakpoint command: "+oa))}}}break;case "c":a.Ba&&(a.Ba.value="");break;case "d":a:{var Ya,Za=f[0],pa=f[1],Ga=f[2],jf=f[3];if("?"==pa){var qa="";for(Ya in Ed)a.Xa[Ya]&&(qa&&(qa+=
","),qa+=Ya);qa+=",state,symbols";a.g("dump memory commands:");a.g("\tdb [a] [#] dump # bytes at address a");a.g("\tdw [a] [#] dump # words at address a");a.g("\tdd [a] [#] dump # dwords at address a");a.g("\tdh [#] [#] dump # instructions from history");qa.length&&a.g("dump extension commands:\n\t"+qa)}else if("state"==pa){var fe=Ne(a.u,!0);"console"==Ga?console.log(fe):(a.Ba&&(a.Ba.value=""),a.g(fe))}else if("symbols"==pa)for(var Jc=0;Jc<a.M.length;Jc++){var Kc=a.M[Jc],ab;for(ab in Kc.ta)if("."!=
ab.charAt(0)){var ge=Kc.ta[ab].o;if(void 0!==ge){var he=Kc.ta[ab].l;he&&(ab=he);a.g(p(ge,4)+" "+ab)}}}else{if("d"==Za){for(Ya in Ed)if(f[1]==Ya){var ie=a.Xa[Ya];ie?(f.shift(),f.shift(),ie(f)):a.g("no dump registered for "+pa);break a}pa||(Za=a.Yb||"db")}else a.Yb=Za;if("dh"==Za){var je=pa,ke=Ga,le="",me=0,K=a.qa,ra=a.V;if(ra.length){var S=+je||a.Db,bb=+ke||10;isNaN(S)?S=bb:le="more ";S>ra.length&&(a.g("note: only "+ra.length+" available"),S=ra.length);K-=S;0>K&&(null==ra[ra.length-1].w?(S=K+S,K=0):
K+=ra.length);var Lc=[];"call"==ke&&(bb=1E5,Lc=["CALL"]);for(void 0!==je&&a.g(S+" instructions earlier:");0<bb&&K!=a.qa;){var ne=ra[K++];if(null==ne.w)break;var ub=X(ne.w),kf=S--,oe=$d(a,ub,"history",kf);(!Lc.length||0<=oe.indexOf(Lc[0]))&&a.g(oe);ub.ob&&(K+=ub.ob,bb-=ub.ob,S-=ub.ob);K>=ra.length&&(K=0);a.Db=S;me++;bb--}}me||(a.g("no "+le+"history available"),a.Db=void 0)}else{var Zb=Z(a,pa);if(Zb){var $b=0;Ga&&("l"==Ga.charAt(0)&&(Ga=Ga.substr(1)||jf),$b=ee(a,Ga)>>>0,65536<$b&&($b=65536));for(var Ha=
"",lf=($b||128)+15>>4||1,Mc="dd"==Za?4:"dw"==Za?2:1,pe=0;pe<lf;pe++){for(var ac=0,Nc=0,vb="",Oc="",pa=p(Zb.w,4),Pc=0;16>Pc;Pc++){var bc=a.wa(Zb,1),ac=ac|bc<<(Nc++<<3);Nc==Mc&&(vb+=p(ac,2*Mc),vb+=1==Mc?7==Pc?"-":" ":" ",ac=Nc=0);Oc+=32<=bc&&128>bc?String.fromCharCode(bc):"."}Ha&&(Ha+="\n");Ha+=pa+" "+vb+" "+Oc}Ha&&a.g(Ha);a.Ab=Zb}}}}break;case "e":if("else"==f[0])break;var cc=1,qe=255,re=a.wa,se=a.wb;"ew"==f[0]&&(cc=2,qe=65535,re=a.jb,se=a.Rb);var te=cc<<1,ue=f[1];if(null==ue)a.g("edit memory commands:"),
a.g("\teb [a] [...] edit bytes at address a"),a.g("\tew [a] [...] edit words at address a");else{var dc=Z(a,ue);if(dc)for(var ec=2;ec<f.length;ec++){var wb=Kd(a,f[ec]);if(void 0===wb){a.g("unrecognized value: "+f[ec]);break}wb&~qe&&a.g("warning: "+p(wb)+" exceeds "+cc+"-byte value");var mf=re.call(a,dc);a.g("changing "+p(dc.w,4)+" from 0x"+p(mf,te)+" to 0x"+p(wb,te));se.call(a,dc,wb,cc)}}break;case "f":Ie(a,f[1]);break;case "g":a:{var ve=f[1],nf=b;if(void 0!==ve){var Qc=Z(a,ve,!0);if(!Qc)break a;
Ld(a,Qc,nf);a.Aa(a.A,Qc,!0)}a.Ga(!0)||c||a.g("cpu busy or unavailable, run command ignored")}break;case "h":var Rc;a.s.fa?(Rc="halting",a.ca()):Rc="already halted";c||a.g(Rc);break;case "i":if("if"==f[0]){var Sc;var xb=b.substr(2),xb=ha(xb);Kd(a,xb)?(c||a.g("true: "+xb),Sc=!0):(c||a.g("false: "+xb),Sc=!1);Sc||(d=!1);break}var Tc=f[1];if(Tc&&"?"!=Tc){var Uc=ee(a,Tc);if(void 0!==Uc){var of=Db(a.B,Uc);a.g(r(Uc)+": "+("0x"+p(of,2)))}}else a.g("input commands:"),a.g("\ti [p]\tread port [p]"),a.g("warning: port accesses can affect hardware state");
break;case "k":var pf=f[0];if("?"==f[1])a.g("stack trace commands:"),a.g("\tk\tshow frame addresses"),a.g("\tks\tshow symbol information");else{var Vc=0,we=X(),yb=X(a.b.Z);for(a.g("stack trace for "+p(yb.w,4));10>Vc;){for(var Ia=null,qf=256;65536>yb.w>>>0;){we.w=a.jb(yb,2);if(null==yb.w||!qf--)break;for(var rf=a,fc=we,xe=null,zb=fc.w,ye=zb,Wc=1;6>=Wc&&zb;Wc++){if(2<Wc){fc.w=zb;var gc=$d(rf,fc);if(0<gc.indexOf("CALL")){var ze=gc.indexOf(" ");if(zb+(gc.indexOf(" ",ze+1)-ze-1)/2==ye){xe=gc;break}}}zb--}fc.w=
ye;if(Ia=xe)break}if(!Ia||null==Ia)break;var Ae=null;if("ks"==pf){var Be=Ia.match(/[0-9A-F]+$/);Be&&(Ae=Ke(a,Be[0]))}Ia=ga(Ia,50)+" ;"+(Ae||"stack="+p(yb.w,4));a.g(Ia);Vc++}Vc||a.g("no return addresses found")}break;case "l":if("ln"==f[0]){Ke(a,f[1],!0);break}break;case "m":a:{var sa,ta=null,B=f[1];"?"==B&&(B=void 0);if(void 0!==B){var Ja=0;if("all"==B)Ja=1610481663,B=null;else if("on"==B)ta=!0,B=null;else if("off"==B)ta=!1,B=null;else{"keys"==B&&(B="key");"kbd"==B&&(B="keyboard");for(sa in Ed)if(B==
sa){Ja=Ed[sa];ta=!!(a.ga&Ja);break}if(!Ja){a.g("unknown message category: "+B);break a}}Ja&&("on"==f[2]?(a.ga|=Ja,ta=!0):"off"==f[2]&&(a.ga&=~Ja,ta=!1))}var sf=0,Ba="";for(sa in Ed)if(!B||B==sa){var tf=!!(a.ga&Ed[sa]);if(null===ta||ta==tf)Ba&&(Ba+=","),++sf%10||(Ba+="\n\t"),"key"==sa&&(sa="keys"),Ba+=sa}void 0===B&&a.g("message commands:\n\tm [category] [on|off]\tturn categories on/off");a.g((null!==ta?ta?"messages on: ":"messages off: ":"message categories:\n\t")+(Ba||"none"));yd(a)}break;case "o":var Xc=
f[1],uf=f[2];if(Xc&&"?"!=Xc){var Yc=ee(a,Xc,"port #"),Zc=ee(a,uf);void 0!==Yc&&void 0!==Zc&&(Hb(a.B,Yc,Zc),a.g(r(Yc)+": "+("0x"+p(Zc,2))))}else a.g("output commands:"),a.g("\to [p] [b]\twrite byte [b] to port [p]"),a.g("warning: port accesses can affect hardware state");break;case "p":if("print"==f[0]){Le(a,b.substr(5));break}var Ce="pr"==f[0]?1:0,vf=1+Ce;if(a.aa)a.g("step in progress");else{var $c=X(a.b.L);switch(a.wa($c)){case 205:a.aa=vf,Gd($c,3)}a.aa?(a.Aa(a.A,$c,!0),a.Ga()||(a.u&&a.u.hb(),a.aa=
0)):Me(a,Ce?"tr":"t")}break;case "r":if("reset"==b){a.u&&a.u.reset();break}Td(a,f);break;case "t":Me(a,f[0],f[1]);break;case "u":Ud(a,f[1],f[2],8);break;case "v":if("var"==f[0]){Je(a,b.substr(3))||(d=!1);break}a.g("PC8080 version 1.21.7 ("+a.b.Ib+",RELEASE"+(kb?",TYPEDARRAYS":",LONGARRAYS")+")");a.g(ua());break;case "x":a:if(f[1]&&"?"!=f[1])switch(f[1]){case "cs":var Ab;void 0!==f[3]&&(Ab=+f[3]);switch(f[2]){case "int":a.b.j.Oa=Ab;break;case "start":a.b.j.ab=Ab;break;case "stop":a.b.j.Qa=Ab;break;
default:a.g("unknown cs option");break a}void 0!==Ab&&mc(a.b);a.g("checksums "+(a.b.s.Ja?"enabled":"disabled"));break;case "sp":void 0!==f[2]&&(rc(a.b,+f[2])||a.g("warning: using 1x multiplier, previous target not reached"));a.g("target speed: "+(a.b.j.Da.toFixed(2)+"Mhz")+" ("+a.b.j.Fa+"x)");break;default:a.g("unknown option: "+f[1])}else a.g("execution options:"),a.g("\tcs int #\tset checksum cycle interval to #"),a.g("\tcs start #\tset checksum cycle start count to #"),a.g("\tcs stop #\tset checksum cycle stop count to #"),
a.g("\tsp #\t\tset speed multiplier to #");break;case "?":if(f[1]){Le(a,b.substr(1));break}var Bb="commands:",ad;for(ad in Ad)Bb+="\n"+ga(ad,7)+Ad[ad];kd(a)||(Bb+="\nnote: frequency/history disabled if no exec breakpoints");a.g(Bb);break;default:a.g("unknown command: "+b),d=!1}}}catch(De){a.g("debugger error: "+(De.stack||De.message)),d=!1}return d}function nc(a,b,c){b=Md(a,b,c);for(var d in b)if(!Zd(a,b[d]))return!1;return!0}
Ma(function(){for(var a=z(document,"pc8080","debugger"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new wd(d);eb(d,c)}});function G(a,b,c){this.id=a.id;this.key=Oe(a,b,c);this.C=a.C;Pe(this,a.Mb)}function Oe(a,b,c){a=a.id;if(b){var d=b.indexOf(".");0<d&&(a+=".v"+b.substr(0,d))}c&&(a+="."+c);return a}
G.prototype={constructor:G,value:function(){return this[this.id]},data:function(){return this[this.id]},toString:function(){var a=this[this.id];return"string"==typeof a?a:JSON.stringify(a)},clear:function(a){Pe(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(e){}for(c=0;c<b.length;c++)if((d=b[c])&&(a||d.substr(0,this.key.length)==this.key)){try{window.localStorage.removeItem(d)}catch(e){}b.splice(c,1);c=0}}};
function Pe(a,b){a[a.id]={};b&&I(a,"parms",b);a.b=!1}function Qe(a){var b=!0;if(xa()){var c=JSON.stringify(a[a.id]);za(a.key,c)||(t("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}function Re(a){var b=!0;try{a[a.id]=JSON.parse(a[a.id])}catch(c){t(c.message||c),b=!1}return b}function Se(a,b){return b?(a[a.id]=b,a.b=!0):a.b?!0:xa()&&(b=ya(a.key))?(a[a.id]=b,a.b=!0):!1}function Te(a,b){return a[a.id][b]||null}function I(a,b,c){try{a[a.id][b]=c}catch(d){}}
function Ue(a,b,c){u.call(this,"Computer",a,Ue,67108864);this.s.da=!1;Ve(this,b);this.Y=kc(this,"autoPower",a);this.F=0;this.pa=a.busWidth||a.buswidth;this.u=We;this.V=null;this.M=this.na=!1;this.qa=kc(this,"url")||"";(Math.random()+.1).toString(36);this.A=Xe(this);if(this.b=db("CPU",this.id)){this.C=db("Debugger",this.id);this.sa=[];for(b=null;b=nb(this,"Video",b);)this.sa.push(b);this.B=new pb({id:this.Bb+".bus",buswidth:this.pa},this.b,this.C);var d,e=cb(this.id);if((this.G=db("Panel",this.id))&&
this.G.Ba)for(b=0;b<e.length;b++)d=e[b],d.ka=this.G.ka,d.g=this.G.g,d.Ba=this.G.Ba;for(b=0;b<e.length;b++)d=e[b],d.Ma&&d.Ma(this,this.B,this.b,this.C);b=null;d=a.resume;void 0!==d&&(1<d.length?b=this.U=d:this.u=parseInt(d,10));var f;if(a=kc(this,"state")||(f=!0,a.state))b=this.aa=a,f||(this.M=!0,this.u=We),this.u&&(this.W=new G(this,Ye),Se(this.W)?b=null:delete this.W);!b&&this.u&&(b=Ze(this))&&(this.M=!0);if(b){var h=this;ma(b,null,!0,function(a,b,c){c?(h.U=null,h.M=!1,h.ka("Unable to load machine state from server (error "+
c+(b?": "+ha(b):"")+")")):(h.V=b,h.na=!0);A(h)})}else A(this);this.N.power||(this.Y=!0);!c&&this.Y&&$e(this,this.fb)}else t("Unable to find CPU component")}x(Ue);var Ye="1.21.7",We=0;function Ve(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){t(d.message+" ("+c+")")}}a.S=b}
function kc(a,b,c){var d=b.toLowerCase(),d=Ra[b]||Ra[d];void 0===d&&a.S&&(d=a.S[b]);void 0===d&&c&&(d=c[b]);void 0===d&&"object"==typeof resources&&resources[b]&&(d=b);return d}function $e(a,b,c){for(var d=cb(a.id),e=0;e<=d.length;e++){var f=e<d.length?d[e]:a;if(!ib(f)){ib(f,function(){$e(a,b,c)});return}}b.call(a,c)}
function af(a,b){var c=new G(a,Ye,"validate");if(Se(c)&&Re(c)){var d=Te(c,"timestamp"),e=b?Te(b,"timestamp"):"unknown";d!=e&&(a.ka("Machine state may be out-of-date\n("+d+" vs. "+e+")\nCheck your browser's local storage limits"),b||c.clear())}}m=Ue.prototype;
m.fb=function(a){void 0===a&&(a=this.u||(this.V?1:We));if(!this.F){this.F++;var b=!1,c=!1;this.ia=!1;var d=this.W||new G(this,Ye);if(-1==a)b=!0;else if(a>We){if(Se(d,this.V)){this.H=new G(this,Ye,"failsafe");Se(this.H)&&(bf(this,d),a=2,Pe(this.H));I(this.H,"timestamp",ka());Qe(this.H);var e=this.u&&!this.M;if(1==a||va("Click OK to restore the previous PC8080 machine state, or CANCEL to reset the machine.")){if(c=Re(d)){var f=Te(d,"code"),h=Te(d,"data");f&&("ok"==f?Se(d,h):("error"==f&&"no machine state"!=
h?(this.ka("Error: "+h),"unable to verify user"==h&&(za("user",""),this.A=null)):this.g(f+": "+h),Pe(d),Se(d)?(c=Re(d),e=!0):c=!1))}e&&af(this,c?d:null)}else 2==a&&d.clear()}else af(this);delete this.V;delete this.W}e=cb(this.id);for(f=0;f<e.length;f++)h=e[f],h!==this&&h!=this.b&&(c=cf(this,h,d,b,c));b=[d,a,c];-1!=a?$e(this,this.Eb,b):this.Eb(b)}};
function cf(a,b,c,d,e){if(!b.s.da){b.s.da=!0;if(b.va){var f=null;e&&((f=Te(c,b.id))||(f=Te(c,b.id.replace(/[a-z0-9]\./i,"."))));"string"===typeof f&&(f=null);!b.va(f,d)&&f&&(t("Unable to restore state for "+b.type),a.aa&&!a.na?(c.clear(),a.u=We,window&&window.location.reload()):a.ia=!0,b.va(null),e=!1)}if(!d&&b.xb)for(a=b.xb.split("|"),c=0;c<a.length;c++)b.status(a[c])}return e}
m.Eb=function(a){var b=a[0],c=0>a[1];a=a[2];this.s.da=!0;var d=this.N.power;d&&(d.textContent="Shutdown");this.ea||(this.g("PC8080 v"+Ye+"\nCopyright \u00a9 2012-2016 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>"),this.ea=!0);this.b&&(cf(this,this.b,b,c,a),oc(this.b));this.ia&&(bf(this,b),b.clear());!c&&this.H&&(this.H.clear(),delete this.H);this.F=0};
function bf(a,b){if(va("There may be a problem with your PC8080 machine.\n\nTo help us diagnose it, click OK to send this PC8080 machine state to http://www.pcjs.org.")){var c=a.qa,d=a.A||"",e=b.toString(),f={app:"PC8080"};f.ver=Ye;f.url=c;f.user=d;f.type="bug";f.data=e;ma("http://www.pcjs.org/api/v1/report",f,!0)}}
function Ne(a,b,c){var d,e="none";if(a.F)return null;a.F--;var f=new G(a,Ye),h=new G(a,Ye,"validate"),g=ka();I(h,"timestamp",g);I(f,"timestamp",g);I(f,"version","1.21.7");I(f,"url",window?window.location.href:null);I(f,"browser",ua());a.b&&a.b.ua&&(c&&a.b.ca(),d=a.b.ua(b,c),"object"===typeof d&&I(f,a.b.id,d),c&&(a.b.s.da=!1,!1===d&&(e=null)));for(var g=cb(a.id),k=0;k<g.length;k++){var l=g[k];l.s.da&&(l.ua&&(d=l.ua(b,c),"object"===typeof d&&I(f,l.id,d)),c&&(l.s.da=!1,!1===d&&(e=null)))}e&&(c?(g=d=
!1,b?(a.A&&df(a,a.A,f.toString()),Qe(h)&&Qe(f)||(e=null,d=g=!0)):a.u&&(d=!0,g=3==a.u),d&&f.clear(g)):e=f.toString());c&&(a.s.da=!1,b=a.N.power)&&(b.textContent="Power");a.F=0;return e}m.reset=function(){this.B&&this.B.reset&&(this.C&&fb(this,0)&&this.C.message("Resetting "+this.B.type,void 0),this.B.reset());for(var a=cb(this.id),b=0;b<a.length;b++){var c=a[b];c!==this&&c!==this.B&&c.reset&&(this.C&&fb(this,0)&&this.C.message("Resetting "+c.type,void 0),c.reset())}};
m.start=function(a,b){for(var c=cb(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.start&&e.start(a,b)}};m.stop=function(a,b){for(var c=cb(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.stop&&e.stop(a,b)}};
m.la=function(a,b,c){var d=this;switch(b){case "power":return this.N[b]=c,c.onclick=function(){d.F||(d.s.da?Ne(d,!1,!0):$e(d,d.fb))},!0;case "reset":return this.N[b]=c,c.onclick=function(){if(d.s.da&&!d.F)if(d.u&&!d.U){var a=va("Click OK to save changes to this PC8080 machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");Ne(d,a,!0);!a&&d.aa?window&&window.location.reload():d.fb(We)}else d.reset(),d.b&&oc(d.b)},!0;case "save":if(da(na(),"pcjs.org")){c.parentNode.removeChild(c);
break}this.N[b]=c;c.onclick=function(){var a=Xe(d,!0);if(a){var b=!!(d.u&&!d.U||d.aa),c=Ne(d,b);b?df(d,a,c):d.ka("Resume disabled, machine state not saved")}};return!0}return!1};
function Xe(a,b){var c=a.A;c||(c=ya("user"),void 0!==c?!c&&b&&(c=null,window&&(c=window.prompt("Saving machine states on the pcjs.org server is currently unsupported.\n\nIf you're running your own server, enter your user ID below.","")),c&&((c=ef(a,c))||a.ka("The user ID is invalid."))):b&&a.ka("Browser local storage is not available"));return c}
function ef(a,b){a.A=null;var c=ma(na()+"/api/v1/user?req=verify&user="+b),d=c[1];if(!c[0]&&d)try{c=eval("("+d+")"),c.code&&"ok"==c.code&&(za("user",c.data),a.A=c.data)}catch(e){t(e.message+" ("+d+")")}return a.A}function Ze(a){var b=null;a.A&&(b=na()+"/api/v1/user?req=load&user="+a.A+"&state="+Oe(a,Ye));return b}
function df(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=Oe(a,Ye);d.data=c;b=ma(na()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var e=d.indexOf("\n");0<e&&(d=d.substr(0,e));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.ka("Machine state saved to server"):c&&(c=b&&b.data||"unable to save machine state",c="error"==b.code?"Error: "+c:"Error "+b.code+": "+c,a.ka(c),za("user",""),a.A=null)}}
function nb(a,b,c){a=cb(a.id);for(var d=0;d<a.length;d++){var e=a[d];if(c)c==e&&(c=null);else if(e.type==b)return e}return null}m.hb=function(){};m.ma=function(a){this.b&&this.b.ma(a);this.G&&this.G.ma(a)};Ma(function(){for(var a=z(document,"pc8080-machine"),b=0;b<a.length;b++)for(var c=a[b],d=y(c),c=z(c,"pc8080","computer"),e=0;e<c.length;e++){var f=c[e],h=y(f),h=new Ue(h,d,!0);eb(h,f);h.Y&&$e(h,h.fb)}});
Ea.show.push(function(){for(var a=z(document,"pc8080","computer"),b=0;b<a.length;b++){var c=y(a[b]);(c=db("Computer",c.id))&&c.ea&&!c.s.da&&c.fb(-1)}});Ea.exit.push(function(){for(var a=z(document,"pc8080","computer"),b=0;b<a.length;b++){var c=y(a[b]);(c=db("Computer",c.id))&&c.s.da&&Ne(c,!(!c.u||c.U),!0)}});var ff=0;function gf(a,b,c,d,e,f){e("Loading "+a+"...");ma(a,null,!0,function(h,g,k){k?(g||(g="unable to load "+a+" ("+k+")"),f(g,null)):wf(g,a,b,c,d,e,f)})}
function wf(a,b,c,d,e,f,h){function g(a,f){if(f)h(f,null);else{if(c){$a(c,b,a);var g=b;g&&0>g.indexOf("/")&&"/"==window.location.pathname.slice(-1)&&(g=window.location.pathname+g);d?"}"==d.slice(-1)?(d=d.slice(0,-1),1<d.length&&(d+=",")):d='{state:"'+d+'",':d="{";d+='url:"'+g+'"}';"object"==typeof resources&&(g=null);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" parms='"+d+"'":"")+(g?' url="'+g+'"':""))}e||(a=a.replace(/(<xsl:variable name="APPCLASS">).*?(<\/xsl:variable>)/,"$1pc8080$2"));
g=null;if("<"==a.charAt(0))try{e||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),window.ActiveXObject||"ActiveXObject"in window?(g=new window.ActiveXObject("Microsoft.XMLDOM"),g.async=!1,g.loadXML(a)):g=(new window.DOMParser).parseFromString(a,"text/xml")}catch(q){g=null,a=q.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);h(a,g)}}a?e?xf(a,f,g):g(a,null):h("no data"+(b?" for file: "+b:""),null)}
function xf(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var e=d[2];b("Loading "+e+"...");ma(e,null,!0,function(f,h,g){if(g||!h)c(a,"unable to resolve XML reference: "+d[0]+" ("+g+")");else{if(f=d[3])if(g=h.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var k=g[0],l,n=/( [a-z]+=)(['"])(.*?)\2/g;l=n.exec(f);)k=0>k.indexOf(l[1])?k.replace(">",l[0]+">"):k.replace(new RegExp(l[1]+"(['\"])(.*?)\\1"),l[0]);g[0]!=k&&(h=h.replace(g[0],k))}else{c(a,"missing <"+d[1]+"> in "+e);return}h=h.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],h);xf(a,b,c)}})}else c(a,null)}
function yf(a,b,c,d){function e(a){if(void 0===g){var b=h&&z(h,"machine-warning");g=b&&b[0]||h}g&&(g.innerHTML=fa(a))}function f(a){e("Error: "+a);k&&(--ff||Oa(!0));k=!1}var h,g,k=!0;ff++;Wa[a]={};try{if(h=document.getElementById(a)){var l;if("object"==typeof resources&&(l=resources.css)){var n=document.head||document.getElementsByTagName("head")[0],q=document.createElement("style");q.type="text/css";q.styleSheet?q.styleSheet.cssText=l:q.appendChild(document.createTextNode(l));n.appendChild(q)}c||
(c="/versions/pc8080/1.21.7/components.xsl");l=function(d,g){g?gf(c,null,null,!1,e,function(d,k){if(k)if($a(a,c,d),e("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var l=g.transformNode(k);l?(h.outerHTML=l,--ff||Oa(!0)):f("transformNodeToObject failed")}else document.implementation&&document.implementation.createDocument?(l=new XSLTProcessor,l.importStylesheet(k),(l=l.transformToFragment(g,document))?h.parentNode?(h.parentNode.replaceChild(l,h),--ff||Oa(!0)):f("invalid machine element: "+
a):f("transformToFragment failed")):f("unable to transform XML: unsupported browser");else f(d)}):f(d)};"<"!=b.charAt(0)?gf(b,a,d,!0,e,l):wf(b,null,a,d,!1,e,l)}else f("missing machine element: "+a)}catch(v){f(v.message)}return k}window.embedPC8080=function(a,b,c,d){Oa(!1);return yf(a,b,c,d)};window.enableEvents=Oa;window.sendEvent=Pa;
function zf(a,b,c,d){if(!c&&b){d.push(b);a=Wa[d[0]];b=null;for(var e in a)if(da(e,"components.xsl")){b=e.replace(".xsl",".css");break}b?ma(b,null,!0,function(a,b){Af(b,d)}):Af(null,d)}else t("Error ("+c+") requesting "+a)}
function Af(a,b){var c,d,e,f=b[0],h=b[1];c=b[4];c=c.match(/^(\s*\(function\(\)\{)([\s\S]*)(}\)\(\);\s*)$/);var g=Wa[f],k={},l;for(l in g){var n=g[l],q=ca(l);if("xml"==q){for(q=/[ \t]*<disk [^>]*path=(['"])(.*?)\1.*?<\/disk>\n?/g;d=q.exec(g[l]);){var v=d[2];v&&(g[v]||(n=n.replace(d[0],"")))}d=l=ba(l)}else"xsl"==q&&(e=l=ba(l));k[l]=n}a&&(k[l="css"]=a);b[2]&&(k[l="parms"]=b[2]);b[3]&&(k[l="state"]=b[3]);d&&e?(l=JSON.stringify(k),h+=".js",c=c[1]+"var resources="+l+";"+c[2]+c[3],c=c.replace(/\u00A9/g,
"&#xA9;"),l=h,g=null,k="data:application/javascript,",k=Aa("Firefox")?k+encodeURIComponent(c):k+encodeURI(c),l&&(g=document.createElement("a"),"string"!=typeof g.download&&(g=null)),g?(g.href=k,g.download=l,document.body.appendChild(g),g.click(),document.body.removeChild(g),c="Check your Downloads folder for "+l+"."):(window.open(k),c="Check your browser for a new window/tab containing the requested data"+(l?" ("+l+")":"")+"."),c+=', copy it to your web server as "'+h+'", and then add the following to your web page:\n\n',
function Rd(a,b,c){var d;if(b){b=Qd(a,b);for(var e=0,f=!1,h=b,g=[],k=[],l=b.split(/(\|\||&&|\||^|&|!=|==|>=|>>>|>>|>|<=|<<|<|-|\+|%|\/|\*)/);e<l.length;){var n=l[e++],q=n.length,n=ha(n);if(!n){f=!0;break}n=Le(a,n,null,!1===c);if(void 0===n){f=!0;c=!1;break}g.push(n);if(e==l.length)break;var n=l[e++],u=n.length;k.length&&Je[n]<Je[k[k.length-1]]&&Ke(g,k,1);k.push(n);b=b.substr(q+u)}Ke(g,k)&&1==g.length||(f=!0);f?c&&a.g("error parsing '"+h+"' at character "+(h.length-b.length)):(d=g.pop(),c&&Me(a,null,
d))}return d}function Qd(a,b){for(var c;(c=b.match(/\{(.*?)}/))&&!(0<=c[1].indexOf("{"));){var d=Rd(a,c[1]);b=b.replace("{"+c[1]+"}",null!=d?p(d):"undefined")}for(;(c=b.match(/\[(.*?)]/))&&!(0<=c[1].indexOf("["));)d=Y(a,c[1]),b=b.replace("["+c[1]+"]",d?p(a.lb(d,0),4):"undefined");for(c=b;d=c.match(/\$([a-z]+)/i);){var e=null;switch(d[1].toLowerCase()){case "ops":e=a.ea-a.Ka}if(null==e)break;c=c.replace(d[0],e.toString())}return c}
function Le(a,b,c,d){var e;void 0!==b?(e=Vd(b),0<=e?e=Xd(a,e):(e=a.pa[b],void 0===e&&(e=aa(b))),void 0!==e||d||a.g("invalid "+(c?c:"value")+": "+b)):d||a.g("missing "+(c||"value"));return e}
function Me(a,b,c){var d,e=!1;if(void 0!==c){e=!0;d=c;var f,h="";if(!f||4<f)f=4;for(var g=0;g<f;g++){h&&(h=","+h);var k=d&255,l=8,n="";void 0===l?l=32:32<l&&(l=32);if(null==k||isNaN(k))for(;0<l--;)n="?"+n;else for(;0<l--;)n=(k&1?"1":"0")+n,k>>=1;h=n+"b"+h;d>>=8}d="0x"+p(c)+" "+c+". ("+h+")"}a.g((null!=b?b+": ":"")+d);return e}function Ne(a,b){if(b)return Me(a,b,a.pa[b]);var c=0;for(b in a.pa)Me(a,b,a.pa[b]),c++;return 0<c}Dd.prototype.Cb=function(a,b){return a[0]>b[0]?1:a[0]<b[0]?-1:0};
function Oe(a,b,c){var d=[],e=X(b)>>>0;for(b=0;b<a.I.length;b++){var f=a.I[b],h=f.A>>>0,g=f.ec;if(e>=h&&e<h+g){e=ia(f.Bb,[e-h],a.Cb);0<=e?Pe(a,b,e,d):c&&(e=~e,Pe(a,b,e-1,d),Pe(a,b,e,d));break}}return d}function Pe(a,b,c,d){var e={},f=a.I[b].Bb,h=0,g=null;0<=c&&c<f.length&&(h=f[c][0],g=f[c][1]);g&&(e=a.I[b].wa[g],g="."==g.charAt(0)?null:e.l||g);d.push(g);d.push(h);d.push(e.a);d.push(e.c)}
function Qe(a,b){if("?"==b)a.g("frequency commands:"),a.g("\tclear\tclear all frequency counts");else{var c,d=0;if(a.S)if("clear"==b){for(c=0;c<a.S.length;c++)a.S[c]=[c,0];a.g("frequency data cleared");d++}else if(void 0!==b)a.g("unknown frequency command: "+b),d++;else{var e=a.S.slice();e.sort(function(a,b){return b[1]-a[1]});for(c=0;c<e.length;c++){var f=e[c][0],h=e[c][1];h&&(a.g((Id[a.zb[f][0]]+" ").substr(0,5)+" ("+("0x"+p(f,2))+"): "+h+" times"),d++)}}d||a.g("no frequency data available")}}
function Re(a,b){var c=b.match(/^\s*([A-Z_]?[A-Z0-9_]*)\s*(=?)\s*(.*)$/i);if(c){if(!c[1])return Ne(a)||a.g("no variables"),!0;if(!c[2])return Ne(a,c[1]);if(!c[3])return delete a.pa[c[1]],!0;var d=Rd(a,c[3]);return void 0!==d?(a.pa[c[1]]=d,!0):!1}a.g("invalid assignment:"+b);return!1}
function Se(a,b,c){var d=null;if(b=Y(a,b,!0)){var e=Oe(a,b,!0);if(e.length){var f,h;e[0]&&(h="",(f=b.A-e[1])&&(h=" + "+r(f)),f=e[0]+" ("+Z(e[1])+")"+h,c&&a.g(f),d=f);4<e.length&&e[4]&&(h="",(f=e[5]-b.A)&&(h=" - "+r(f)),f=e[4]+" ("+Z(e[5])+")"+h,c&&a.g(f),d||(d=f))}else c&&a.g("no symbols")}return d}
function $d(a,b){var c;if(b&&"?"==b[1])a.g("register commands:"),a.g("\tr\tdump registers"),a.g("\trx [#]\tset flag or register x to [#]");else{var d=a.b;null==c&&(c=!0);if(null!=b&&1<b.length){var e=b[1],f=null,h=e.indexOf("=");if(0<h)f=e.substr(h+1),e=e.substr(0,h);else if(2<b.length)f=b[2];else{a.g("missing value for "+b[1]);return}var h=!1,g=Rd(a,f);if(void 0!==g){var h=!0,k=e.toUpperCase();"E"==k.charAt(0)&&(k=null);switch(k){case "A":d.j=g&255;break;case "B":d.K=g&255;break;case "BC":d.K=g>>
8&255;case "C":d.N=g&255;break;case "D":d.L=g&255;break;case "DE":d.L=g>>8&255;case "E":d.O=g&255;break;case "H":d.M=g&255;break;case "HL":d.M=g>>8&255;case "L":d.P=g&255;break;case "SP":d.aa=g&65535;break;case "PC":E(d,g);a.Y=V(d.J);break;case "PS":Ac(d,g);break;case "C":d.F=g?d.F|256:d.F&255;break;case "P":g?Gc(d)||(d.V^=1):Gc(d)&&(d.V^=1);break;case "A":d.ca=g?~d.V&16|d.ca&-17:d.V&16|d.ca&-17;break;case "Z":d.F=g?d.F&-256:d.F|255;break;case "S":g?Jc(d)||(d.V^=192):Jc(d)&&(d.V^=192);break;case "I":d.la=
g?d.la|512:d.la&-513;break;default:a.g("unknown register: "+e);return}}if(!h){a.g("invalid value: "+f);return}D(d);a.g("updated registers:")}a.g(je(a));c&&(a.Y=V(d.J),ae(a,Z(a.Y.A)))}}function Te(a,b){b=ha(b);var c=b.match(/^(['"])(.*?)\1$/);c?a.g(Yd(a,c[2])):Rd(a,b,!0)}function Ue(a,b,c){var d="t"!=b;c=Le(a,c,null,!0)||1;var e=1==c?0:1;"tc"==b&&(e=c,c=1);Ca(c,function(){return jb(a,!0)&&a.Wa(e,d,!1)},function(){D(a.b);jb(a,!1)})}
function ae(a,b,c,d){if(b=Y(a,b,!0)){void 0===d&&(d=1);var e=256;if(void 0!==c){d=Y(a,c,!0);if(!d||d.A<b.A)return;e=d.A-b.A;if(256<e){a.g("range too large");return}d=-1}c=0;for(var f;0<e&&d--;){f=kb(a,!1)||a.ba?a.T:null;var h=null!=f?"cycles":null,g=Oe(a,b),k=b.A;if(g[0]&&d&&(!c&&d||0>g[0].indexOf("+"))){var l=g[0]+":";g[2]&&(l+=" "+g[2]);a.g(l)}g[3]&&(h=g[3],f=null);f=ge(a,b,h,f);a.g(f);a.Y=b;e-=b.A-k;c++}}}
function Td(a,b,c,d){if(c)if(b){0>a.G&&a.D.length&&(a.G=0);if(0>a.G||b!=a.D[a.G])a.D.splice(0,0,b),a.G=0;a.G--}else b=a.D[a.G+1];a=[];if(b){b=b.toLowerCase().replace(/""/g,"'");c=0;var e=null;d=d||";";for(var f=0;f<=b.length;f++){var h=b.charAt(f);if('"'==h||"'"==h)e?h==e&&(e=null):e=h;else if(h==d&&!e||!h)a.push(ha(b.substring(c,f))),c=f+1}}return a}
function fe(a,b,c){var d=!0;try{b.length&&"end"!=b?c||a.g(">> "+b):(a.qa&&(a.g("ended assemble at "+Z(a.na.A)),a.Y=a.na,a.qa=!1),b="");var e=b.charAt(0);if('"'==e||"'"==e)return!0;a.Ba=null;if(lb(a)&&0<b.length){a.qa&&(b="a "+Z(a.na.A)+" "+b);var f=b.replace(/ +/g," ").split(" ");if(f&&f.length)for(var h=f[0],g=h.charAt(0),k=1;k<h.length;k++){var l=h.charAt(k);if("?"==g||"r"==g||"a">l||"z"<l){f[0]=h.substr(k);f.unshift(h.substr(0,k));break}}switch(f[0].charAt(0)){case "a":var n=Y(a,f[1],!0);if(n)if(a.na=
n,void 0===f[2])a.g("begin assemble at "+Z(n.A)),a.qa=!0,D(a.b);else{var q;a.g("not supported yet");q=[];if(q.length){for(var u=0;u<q.length;u++)a.yb(n,q[u],1);a.g(ge(a,a.na))}}break;case "b":a:{var W=f[0],R=f[1],qa=b;if("?"==R)a.g("breakpoint commands:"),a.g("\tbi [p]\ttoggle break on input port [p]"),a.g("\tbo [p]\ttoggle break on output port [p]"),a.g("\tbp [a]\tset exec breakpoint at addr [a]"),a.g("\tbr [a]\tset read breakpoint at addr [a]"),a.g("\tbw [a]\tset write breakpoint at addr [a]"),
a.g("\tbc [a]\tclear breakpoint at addr [a]"),a.g("\tbl\tlist all breakpoints"),a.g("\tbn [n]\tbreak after [n] instruction(s)");else{var sa=W.charAt(1);if("l"==sa){var ab=0,ab=ab+ee(a,a.w),ab=ab+ee(a,a.Z);(ab+=ee(a,a.H))||a.g("no breakpoints")}else if("n"==sa)a.Aa=Le(a,R),a.g("break after "+a.Aa+" instruction(s)");else if(void 0===R)a.g("missing breakpoint address");else{var F=V();if("*"!=R&&(F=Y(a,R,!0),!F))break a;R=r(F.A);"c"==sa?null==F.A?(Ed(a),a.g("all breakpoints cleared")):ce(a,a.w,F)||ce(a,
a.Z,F)||ce(a,a.H,F)||a.g("breakpoint missing: "+Z(F.A)):"i"==sa?a.g("breakpoint "+(Fb(a.B,F.A)?"enabled":"cleared")+": port "+R+" (input)"):"o"==sa?a.g("breakpoint "+(Ib(a.B,F.A)?"enabled":"cleared")+": port "+R+" (output)"):null!=F.A&&(Sd(a,F,qa),"p"==sa?a.Ca(a.w,F):"r"==sa?a.Ca(a.Z,F):"w"==sa?a.Ca(a.H,F):a.g("unknown breakpoint command: "+sa))}}}break;case "c":a.Da&&(a.Da.value="");break;case "d":a:{var bb,cb=f[0],ta=f[1],Ka=f[2],qf=f[3];if("?"==ta){var ua="";for(bb in Ld)a.Za[bb]&&(ua&&(ua+=","),
ua+=bb);ua+=",state,symbols";a.g("dump memory commands:");a.g("\tdb [a] [#] dump # bytes at address a");a.g("\tdw [a] [#] dump # words at address a");a.g("\tdd [a] [#] dump # dwords at address a");a.g("\tdh [#] [#] dump # instructions from history");ua.length&&a.g("dump extension commands:\n\t"+ua)}else if("state"==ta){var ke=Ve(a.s,!0);"console"==Ka?console.log(ke):(a.Da&&(a.Da.value=""),a.g(ke))}else if("symbols"==ta)for(var Nc=0;Nc<a.I.length;Nc++){var Oc=a.I[Nc],eb;for(eb in Oc.wa)if("."!=
eb.charAt(0)){var le=Oc.wa[eb].o;if(void 0!==le){var me=Oc.wa[eb].l;me&&(eb=me);a.g(Z(le)+" "+eb)}}}else{if("d"==cb){for(bb in Ld)if(f[1]==bb){var ne=a.Za[bb];ne?(f.shift(),f.shift(),ne(f)):a.g("no dump registered for "+ta);break a}ta||(cb=a.$b||"db")}else a.$b=cb;if("dh"==cb){var oe=ta,pe=Ka,qe="",re=0,N=a.ra,va=a.W;if(va.length){var S=+oe||a.Hb,fb=+pe||10;isNaN(S)?S=fb:qe="more ";S>va.length&&(a.g("note: only "+va.length+" available"),S=va.length);N-=S;0>N&&(null==va[va.length-1].A?(S=N+S,N=0):
N+=va.length);var Pc=[];"call"==pe&&(fb=1E5,Pc=["CALL"]);for(void 0!==oe&&a.g(S+" instructions earlier:");0<fb&&N!=a.ra;){var se=va[N++];if(null==se.A)break;var xb=V(se.A),rf=S--,te=ge(a,xb,"history",rf);(!Pc.length||0<=te.indexOf(Pc[0]))&&a.g(te);xb.qb&&(N+=xb.qb,fb-=xb.qb,S-=xb.qb);N>=va.length&&(N=0);a.Hb=S;re++;fb--}}re||(a.g("no "+qe+"history available"),a.Hb=void 0)}else{var cc=Y(a,ta);if(cc){var dc=0;Ka&&("l"==Ka.charAt(0)&&(Ka=Ka.substr(1)||qf),dc=Le(a,Ka)>>>0,65536<dc&&(dc=65536));for(var La=
"",sf=(dc||128)+15>>4||1,Qc="dd"==cb?4:"dw"==cb?2:1,ue=0;ue<sf;ue++){for(var ec=0,Rc=0,yb="",Sc="",ta=Z(cc.A),Tc=0;16>Tc;Tc++){var fc=a.U(cc,1),ec=ec|fc<<(Rc++<<3);Rc==Qc&&(yb+=p(ec,2*Qc),yb+=1==Qc?7==Tc?"-":" ":" ",ec=Rc=0);Sc+=32<=fc&&128>fc?String.fromCharCode(fc):"."}La&&(La+="\n");La+=ta+" "+yb+" "+Sc}La&&a.g(La);a.Db=cc}}}}break;case "e":if("else"==f[0])break;var gc=1,ve=255,we=a.U,xe=a.yb;"ew"==f[0]&&(gc=2,ve=65535,we=a.lb,xe=a.Sb);var ye=gc<<1,ze=f[1];if(null==ze)a.g("edit memory commands:"),
a.g("\teb [a] [...] edit bytes at address a"),a.g("\tew [a] [...] edit words at address a");else{var hc=Y(a,ze);if(hc)for(var ic=2;ic<f.length;ic++){var zb=Rd(a,f[ic]);if(void 0===zb){a.g("unrecognized value: "+f[ic]);break}zb&~ve&&a.g("warning: "+p(zb)+" exceeds "+gc+"-byte value");var tf=we.call(a,hc);a.g("changing "+Z(hc.A)+" from 0x"+p(tf,ye)+" to 0x"+p(zb,ye));xe.call(a,hc,zb,gc)}}break;case "f":Qe(a,f[1]);break;case "g":a:{var Ae=f[1],uf=b;if(void 0!==Ae){var Uc=Y(a,Ae,!0);if(!Uc)break a;
Sd(a,Uc,uf);a.Ca(a.w,Uc,!0)}a.Ja(!0)||c||a.g("cpu busy or unavailable, run command ignored")}break;case "h":var Vc;a.u.ha?(Vc="halting",a.da()):Vc="already halted";c||a.g(Vc);break;case "i":if("if"==f[0]){var Wc;var Ab=b.substr(2),Ab=ha(Ab);Rd(a,Ab)?(c||a.g("true: "+Ab),Wc=!0):(c||a.g("false: "+Ab),Wc=!1);Wc||(d=!1);break}var Xc=f[1];if(Xc&&"?"!=Xc){var Yc=Le(a,Xc);if(void 0!==Yc){var vf=Gb(a.B,Yc);a.g(r(Yc)+": "+("0x"+p(vf,2)))}}else a.g("input commands:"),a.g("\ti [p]\tread port [p]"),a.g("warning: port accesses can affect hardware state");
break;case "k":var wf=f[0];if("?"==f[1])a.g("stack trace commands:"),a.g("\tk\tshow frame addresses"),a.g("\tks\tshow symbol information");else{var Zc=0,Be=V(),Bb=V(a.b.aa);for(a.g("stack trace for "+Z(Bb.A));10>Zc;){for(var Ma=null,xf=256;65536>Bb.A>>>0;){Be.A=a.lb(Bb,2);if(null==Bb.A||!xf--)break;for(var yf=a,jc=Be,Ce=null,Cb=jc.A,De=Cb,$c=1;6>=$c&&Cb;$c++){if(2<$c){jc.A=Cb;var kc=ge(yf,jc);if(0<kc.indexOf("CALL")){var Ee=kc.indexOf(" ");if(Cb+(kc.indexOf(" ",Ee+1)-Ee-1)/2==De){Ce=kc;break}}}Cb--}jc.A=
De;if(Ma=Ce)break}if(!Ma||null==Ma)break;var Fe=null;if("ks"==wf){var Ge=Ma.match(/[0-9A-F]+$/);Ge&&(Fe=Se(a,Ge[0]))}Ma=ga(Ma,50)+" ;"+(Fe||"stack="+Z(Bb.A));a.g(Ma);Zc++}Zc||a.g("no return addresses found")}break;case "l":if("ln"==f[0]){Se(a,f[1],!0);break}break;case "m":a:{var wa,xa=null,A=f[1];"?"==A&&(A=void 0);if(void 0!==A){var Na=0;if("all"==A)Na=1610481663,A=null;else if("on"==A)xa=!0,A=null;else if("off"==A)xa=!1,A=null;else{"keys"==A&&(A="key");"kbd"==A&&(A="keyboard");for(wa in Ld)if(A==
wa){Na=Ld[wa];xa=!!(a.fa&Na);break}if(!Na){a.g("unknown message category: "+A);break a}}Na&&("on"==f[2]?(a.fa|=Na,xa=!0):"off"==f[2]&&(a.fa&=~Na,xa=!1))}var zf=0,Fa="";for(wa in Ld)if(!A||A==wa){var Af=!!(a.fa&Ld[wa]);if(null===xa||xa==Af)Fa&&(Fa+=","),++zf%10||(Fa+="\n\t"),"key"==wa&&(wa="keys"),Fa+=wa}void 0===A&&a.g("message commands:\n\tm [category] [on|off]\tturn categories on/off");a.g((null!==xa?xa?"messages on: ":"messages off: ":"message categories:\n\t")+(Fa||"none"));Fd(a)}break;case "o":var ad=
f[1],Bf=f[2];if(ad&&"?"!=ad){var bd=Le(a,ad,"port #"),cd=Le(a,Bf);void 0!==bd&&void 0!==cd&&(Jb(a.B,bd,cd),a.g(r(bd)+": "+("0x"+p(cd,2))))}else a.g("output commands:"),a.g("\to [p] [b]\twrite byte [b] to port [p]"),a.g("warning: port accesses can affect hardware state");break;case "p":if("print"==f[0]){Te(a,b.substr(5));break}var He="pr"==f[0]?1:0,Cf=1+He;if(a.ba)a.g("step in progress");else{var dd=V(a.b.J);switch(a.U(dd)){case 205:a.ba=Cf,Nd(dd,3)}a.ba?(a.Ca(a.w,dd,!0),a.Ja()||(a.s&&a.s.jb(),a.ba=
0)):Ue(a,He?"tr":"t")}break;case "r":if("reset"==b){a.s&&a.s.reset();break}$d(a,f);break;case "t":Ue(a,f[0],f[1]);break;case "u":ae(a,f[1],f[2],8);break;case "v":if("var"==f[0]){Re(a,b.substr(3))||(d=!1);break}a.g("PC8080 version 1.21.7 ("+a.b.Pa+",RELEASE"+(nb?",TYPEDARRAYS":",LONGARRAYS")+")");a.g(oa());break;case "x":a:if(f[1]&&"?"!=f[1])switch(f[1]){case "cs":var Db;void 0!==f[3]&&(Db=+f[3]);switch(f[2]){case "int":a.b.i.Ra=Db;break;case "start":a.b.i.cb=Db;break;case "stop":a.b.i.Ta=Db;break;
default:a.g("unknown cs option");break a}void 0!==Db&&oc(a.b);a.g("checksums "+(a.b.u.Ma?"enabled":"disabled"));break;case "sp":void 0!==f[2]&&(tc(a.b,+f[2])||a.g("warning: using 1x multiplier, previous target not reached"));a.g("target speed: "+(a.b.i.Fa.toFixed(2)+"Mhz")+" ("+a.b.i.Ha+"x)");break;default:a.g("unknown option: "+f[1])}else a.g("execution options:"),a.g("\tcs int #\tset checksum cycle interval to #"),a.g("\tcs start #\tset checksum cycle start count to #"),a.g("\tcs stop #\tset checksum cycle stop count to #"),
a.g("\tsp #\t\tset speed multiplier to #");break;case "?":if(f[1]){Te(a,b.substr(1));break}var Eb="commands:",ed;for(ed in Hd)Eb+="\n"+ga(ed,7)+Hd[ed];od(a)||(Eb+="\nnote: frequency/history disabled if no exec breakpoints");a.g(Eb);break;default:a.g("unknown command: "+b),d=!1}}}catch(Ie){a.g("debugger error: "+(Ie.stack||Ie.message)),d=!1}return d}function pc(a,b,c){b=Td(a,b,c);for(var d in b)if(!fe(a,b[d]))return!1;return!0}
Ja(function(){for(var a=z(document,"pc8080","debugger"),b=0;b<a.length;b++){var c=a[b],d=y(c),d=new Dd(d);db(d,c)}});function G(a,b,c){this.id=a.id;this.key=We(a,b,c);this.C=a.C;Xe(this,a.Ob)}function We(a,b,c){a=a.id;if(b){var d=b.indexOf(".");0<d&&(a+=".v"+b.substr(0,d))}c&&(a+="."+c);return a}
G.prototype={constructor:G,value:function(){return this[this.id]},data:function(){return this[this.id]},toString:function(){var a=this[this.id];return"string"==typeof a?a:JSON.stringify(a)},clear:function(a){Xe(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(e){}for(c=0;c<b.length;c++)if((d=b[c])&&(a||d.substr(0,this.key.length)==this.key)){try{window.localStorage.removeItem(d)}catch(e){}b.splice(c,1);c=0}}};
function Xe(a,b){a[a.id]={};b&&H(a,"parms",b);a.b=!1}function Ye(a){var b=!0;if(ya()){var c=JSON.stringify(a[a.id]);Aa(a.key,c)||(t("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}function Ze(a){var b=!0;try{a[a.id]=JSON.parse(a[a.id])}catch(c){t(c.message||c),b=!1}return b}function $e(a,b){return b?(a[a.id]=b,a.b=!0):a.b?!0:ya()&&(b=za(a.key))?(a[a.id]=b,a.b=!0):!1}function af(a,b){return a[a.id][b]||null}function H(a,b,c){try{a[a.id][b]=c}catch(d){}}
function bf(a,b,c){v.call(this,"Computer",a,bf,67108864);this.u.ga=!1;cf(this,b);this.ba=mc(this,"autoPower",a);this.D=0;this.ra=a.busWidth||a.buswidth;this.s=df;this.W=null;this.I=this.qa=!1;this.va=mc(this,"url")||"";(Math.random()+.1).toString(36);this.w=ef(this);if(this.b=$a("CPU",this.id)){this.C=$a("Debugger",this.id);this.Z=[];for(b=null;b=qb(this,"Video",b);)this.Z.push(b);this.B=new sb({id:this.Eb+".bus",buswidth:this.ra},this.b,this.C);var d,e=Za(this.id);if((this.G=$a("Panel",this.id))&&
this.G.Da)for(b=0;b<e.length;b++)d=e[b],d.ka=this.G.ka,d.g=this.G.g,d.Da=this.G.Da;for(b=0;b<e.length;b++)d=e[b],d.za&&d.za(this,this.B,this.b,this.C);b=null;d=a.resume;void 0!==d&&(1<d.length?b=this.T=d:this.s=parseInt(d,10));var f;if(a=mc(this,"state")||(f=!0,a.state))b=this.ea=a,f||(this.I=!0,this.s=df),this.s&&(this.Y=new G(this,ff),$e(this.Y)?b=null:delete this.Y);!b&&this.s&&(b=gf(this))&&(this.I=!0);if(b){var h=this;ma(b,null,!0,function(a,b,c){c?(h.T=null,h.I=!1,h.ka("Unable to load machine state from server (error "+
c+(b?": "+ha(b):"")+")")):(h.W=b,h.qa=!0);B(h)})}else B(this);this.R.power||(this.ba=!0);!c&&this.ba&&hf(this,this.hb)}else t("Unable to find CPU component")}x(bf);var ff="1.21.7",df=0;function cf(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){t(d.message+" ("+c+")")}}a.S=b}
function mc(a,b,c){var d=b.toLowerCase(),d=Sa[b]||Sa[d];void 0===d&&a.S&&(d=a.S[b]);void 0===d&&c&&(d=c[b]);void 0===d&&"object"==typeof resources&&resources[b]&&(d=b);return d}function hf(a,b,c){for(var d=Za(a.id),e=0;e<=d.length;e++){var f=e<d.length?d[e]:a;if(!lb(f)){lb(f,function(){hf(a,b,c)});return}}b.call(a,c)}
function jf(a,b){var c=new G(a,ff,"validate");if($e(c)&&Ze(c)){var d=af(c,"timestamp"),e=b?af(b,"timestamp"):"unknown";d!=e&&(a.ka("Machine state may be out-of-date\n("+d+" vs. "+e+")\nCheck your browser's local storage limits"),b||c.clear())}}m=bf.prototype;
m.hb=function(a){void 0===a&&(a=this.s||(this.W?1:df));if(!this.D){this.D++;var b=!1,c=!1;this.pa=!1;var d=this.Y||new G(this,ff);if(-1==a)b=!0;else if(a>df){if($e(d,this.W)){this.H=new G(this,ff,"failsafe");$e(this.H)&&(kf(this,d),a=2,Xe(this.H));H(this.H,"timestamp",ka());Ye(this.H);var e=this.s&&!this.I;if(1==a||pa("Click OK to restore the previous PC8080 machine state, or CANCEL to reset the machine.")){if(c=Ze(d)){var f=af(d,"code"),h=af(d,"data");f&&("ok"==f?$e(d,h):("error"==f&&"no machine state"!=
h?(this.ka("Error: "+h),"unable to verify user"==h&&(Aa("user",""),this.w=null)):this.g(f+": "+h),Xe(d),$e(d)?(c=Ze(d),e=!0):c=!1))}e&&jf(this,c?d:null)}else 2==a&&d.clear()}else jf(this);delete this.W;delete this.Y}e=Za(this.id);for(f=0;f<e.length;f++)h=e[f],h!==this&&h!=this.b&&(c=lf(this,h,d,b,c));b=[d,a,c];-1!=a?hf(this,this.Gb,b):this.Gb(b)}};
function lf(a,b,c,d,e){if(!b.u.ga){b.u.ga=!0;if(b.ua){var f=null;e&&((f=af(c,b.id))||(f=af(c,b.id.replace(/[a-z0-9]\./i,"."))));"string"===typeof f&&(f=null);!b.ua(f,d)&&f&&(t("Unable to restore state for "+b.type),a.ea&&!a.qa?(c.clear(),a.s=df,window&&window.location.reload()):a.pa=!0,b.ua(null),e=!1)}if(!d&&b.Ab)for(a=b.Ab.split("|"),c=0;c<a.length;c++)b.status(a[c])}return e}
m.Gb=function(a){var b=a[0],c=0>a[1];a=a[2];this.u.ga=!0;var d=this.R.power;d&&(d.textContent="Shutdown");this.na||(this.g("PC8080 v"+ff+"\nCopyright \u00a9 2012-2016 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>"),this.na=!0);this.b&&(lf(this,this.b,b,c,a),qc(this.b));this.pa&&(kf(this,b),b.clear());!c&&this.H&&(this.H.clear(),delete this.H);this.D=0};
function kf(a,b){if(pa("There may be a problem with your PC8080 machine.\n\nTo help us diagnose it, click OK to send this PC8080 machine state to http://www.pcjs.org.")){var c=a.va,d=a.w||"",e=b.toString(),f={app:"PC8080"};f.ver=ff;f.url=c;f.user=d;f.type="bug";f.data=e;ma("http://www.pcjs.org/api/v1/report",f,!0)}}
function Ve(a,b,c){var d,e="none";if(a.D)return null;a.D--;var f=new G(a,ff),h=new G(a,ff,"validate"),g=ka();H(h,"timestamp",g);H(f,"timestamp",g);H(f,"version","1.21.7");H(f,"url",window?window.location.href:null);H(f,"browser",oa());a.b&&a.b.ta&&(c&&a.b.da(),d=a.b.ta(b,c),"object"===typeof d&&H(f,a.b.id,d),c&&(a.b.u.ga=!1,!1===d&&(e=null)));for(var g=Za(a.id),k=0;k<g.length;k++){var l=g[k];l.u.ga&&(l.ta&&(d=l.ta(b,c),"object"===typeof d&&H(f,l.id,d)),c&&(l.u.ga=!1,!1===d&&(e=null)))}e&&(c?(g=d=
!1,b?(a.w&&mf(a,a.w,f.toString()),Ye(h)&&Ye(f)||(e=null,d=g=!0)):a.s&&(d=!0,g=3==a.s),d&&f.clear(g)):e=f.toString());c&&(a.u.ga=!1,b=a.R.power)&&(b.textContent="Power");a.D=0;return e}m.reset=function(){this.B&&this.B.reset&&(this.C&&ib(this,0)&&this.C.message("Resetting "+this.B.type,void 0),this.B.reset());for(var a=Za(this.id),b=0;b<a.length;b++){var c=a[b];c!==this&&c!==this.B&&c.reset&&(this.C&&ib(this,0)&&this.C.message("Resetting "+c.type,void 0),c.reset())}};
m.start=function(a,b){for(var c=Za(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.start&&e.start(a,b)}};m.stop=function(a,b){for(var c=Za(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.stop&&e.stop(a,b)}};
m.ma=function(a,b,c){var d=this;switch(b){case "power":return this.R[b]=c,c.onclick=function(){d.D||(d.u.ga?Ve(d,!1,!0):hf(d,d.hb))},!0;case "reset":return this.R[b]=c,c.onclick=function(){if(d.u.ga&&!d.D)if(d.s&&!d.T){var a=pa("Click OK to save changes to this PC8080 machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");Ve(d,a,!0);!a&&d.ea?window&&window.location.reload():d.hb(df)}else d.reset(),d.b&&qc(d.b)},!0;case "save":if(da(na(),"pcjs.org")){c.parentNode.removeChild(c);
break}this.R[b]=c;c.onclick=function(){var a=ef(d,!0);if(a){var b=!!(d.s&&!d.T||d.ea),c=Ve(d,b);b?mf(d,a,c):d.ka("Resume disabled, machine state not saved")}};return!0}return!1};
function ef(a,b){var c=a.w;c||(c=za("user"),void 0!==c?!c&&b&&(c=null,window&&(c=window.prompt("Saving machine states on the pcjs.org server is currently unsupported.\n\nIf you're running your own server, enter your user ID below.","")),c&&((c=nf(a,c))||a.ka("The user ID is invalid."))):b&&a.ka("Browser local storage is not available"));return c}
function nf(a,b){a.w=null;var c=ma(na()+"/api/v1/user?req=verify&user="+b),d=c[1];if(!c[0]&&d)try{c=eval("("+d+")"),c.code&&"ok"==c.code&&(Aa("user",c.data),a.w=c.data)}catch(e){t(e.message+" ("+d+")")}return a.w}function gf(a){var b=null;a.w&&(b=na()+"/api/v1/user?req=load&user="+a.w+"&state="+We(a,ff));return b}
function mf(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=We(a,ff);d.data=c;b=ma(na()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var e=d.indexOf("\n");0<e&&(d=d.substr(0,e));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.ka("Machine state saved to server"):c&&(c=b&&b.data||"unable to save machine state",c="error"==b.code?"Error: "+c:"Error "+b.code+": "+c,a.ka(c),Aa("user",""),a.w=null)}}
function qb(a,b,c){a=Za(a.id);for(var d=0;d<a.length;d++){var e=a[d];if(c)c==e&&(c=null);else if(e.type==b)return e}return null}m.jb=function(){};m.oa=function(a){this.b&&this.b.oa(a);this.G&&this.G.oa(a)};function wc(a,b){for(var c=0;c<a.Z.length;c++){var d=a.Z[c];b&1?(d=d.b,d.w=d.w&-8|10):(d=d.b,d.w=d.w&-8|9)}}
Ja(function(){for(var a=z(document,"pc8080-machine"),b=0;b<a.length;b++)for(var c=a[b],d=y(c),c=z(c,"pc8080","computer"),e=0;e<c.length;e++){var f=c[e],h=y(f),h=new bf(h,d,!0);db(h,f);h.ba&&hf(h,h.hb)}});Ea.show.push(function(){for(var a=z(document,"pc8080","computer"),b=0;b<a.length;b++){var c=y(a[b]);(c=$a("Computer",c.id))&&c.na&&!c.u.ga&&c.hb(-1)}});
Ea.exit.push(function(){for(var a=z(document,"pc8080","computer"),b=0;b<a.length;b++){var c=y(a[b]);(c=$a("Computer",c.id))&&c.u.ga&&Ve(c,!(!c.s||c.T),!0)}});var of=0;function pf(a,b,c,d,e,f){e("Loading "+a+"...");ma(a,null,!0,function(h,g,k){k?(g||(g="unable to load "+a+" ("+k+")"),f(g,null)):Df(g,a,b,c,d,e,f)})}
function Df(a,b,c,d,e,f,h){function g(a,f){if(f)h(f,null);else{if(c){Ya(c,b,a);var g=b;g&&0>g.indexOf("/")&&"/"==window.location.pathname.slice(-1)&&(g=window.location.pathname+g);d?"}"==d.slice(-1)?(d=d.slice(0,-1),1<d.length&&(d+=",")):d='{state:"'+d+'",':d="{";d+='url:"'+g+'"}';"object"==typeof resources&&(g=null);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" parms='"+d+"'":"")+(g?' url="'+g+'"':""))}e||(a=a.replace(/(<xsl:variable name="APPCLASS">).*?(<\/xsl:variable>)/,"$1pc8080$2"));
g=null;if("<"==a.charAt(0))try{e||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),window.ActiveXObject||"ActiveXObject"in window?(g=new window.ActiveXObject("Microsoft.XMLDOM"),g.async=!1,g.loadXML(a)):g=(new window.DOMParser).parseFromString(a,"text/xml")}catch(q){g=null,a=q.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);h(a,g)}}a?e?Ef(a,f,g):g(a,null):h("no data"+(b?" for file: "+b:""),null)}
function Ef(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var e=d[2];b("Loading "+e+"...");ma(e,null,!0,function(f,h,g){if(g||!h)c(a,"unable to resolve XML reference: "+d[0]+" ("+g+")");else{if(f=d[3])if(g=h.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var k=g[0],l,n=/( [a-z]+=)(['"])(.*?)\2/g;l=n.exec(f);)k=0>k.indexOf(l[1])?k.replace(">",l[0]+">"):k.replace(new RegExp(l[1]+"(['\"])(.*?)\\1"),l[0]);g[0]!=k&&(h=h.replace(g[0],k))}else{c(a,"missing <"+d[1]+"> in "+e);return}h=h.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],h);Ef(a,b,c)}})}else c(a,null)}
function Ff(a,b,c,d){function e(a){if(void 0===g){var b=h&&z(h,"machine-warning");g=b&&b[0]||h}g&&(g.innerHTML=fa(a))}function f(a){e("Error: "+a);k&&(--of||Pa(!0));k=!1}var h,g,k=!0;of++;Xa[a]={};try{if(h=document.getElementById(a)){var l;if("object"==typeof resources&&(l=resources.css)){var n=document.head||document.getElementsByTagName("head")[0],q=document.createElement("style");q.type="text/css";q.styleSheet?q.styleSheet.cssText=l:q.appendChild(document.createTextNode(l));n.appendChild(q)}c||
(c="/versions/pc8080/1.21.7/components.xsl");l=function(d,g){g?pf(c,null,null,!1,e,function(d,k){if(k)if(Ya(a,c,d),e("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var l=g.transformNode(k);l?(h.outerHTML=l,--of||Pa(!0)):f("transformNodeToObject failed")}else document.implementation&&document.implementation.createDocument?(l=new XSLTProcessor,l.importStylesheet(k),(l=l.transformToFragment(g,document))?h.parentNode?(h.parentNode.replaceChild(l,h),--of||Pa(!0)):f("invalid machine element: "+
a):f("transformToFragment failed")):f("unable to transform XML: unsupported browser");else f(d)}):f(d)};"<"!=b.charAt(0)?pf(b,a,d,!0,e,l):Df(b,null,a,d,!1,e,l)}else f("missing machine element: "+a)}catch(u){f(u.message)}return k}window.embedPC8080=function(a,b,c,d){Pa(!1);return Ff(a,b,c,d)};window.enableEvents=Pa;window.sendEvent=Qa;
function Gf(a,b,c,d){if(!c&&b){d.push(b);a=Xa[d[0]];b=null;for(var e in a)if(da(e,"components.xsl")){b=e.replace(".xsl",".css");break}b?ma(b,null,!0,function(a,b){Hf(b,d)}):Hf(null,d)}else t("Error ("+c+") requesting "+a)}
function Hf(a,b){var c,d,e,f=b[0],h=b[1];c=b[4];c=c.match(/^(\s*\(function\(\)\{)([\s\S]*)(}\)\(\);\s*)$/);var g=Xa[f],k={},l;for(l in g){var n=g[l],q=ca(l);if("xml"==q){for(q=/[ \t]*<disk [^>]*path=(['"])(.*?)\1.*?<\/disk>\n?/g;d=q.exec(g[l]);){var u=d[2];u&&(g[u]||(n=n.replace(d[0],"")))}d=l=ba(l)}else"xsl"==q&&(e=l=ba(l));k[l]=n}a&&(k[l="css"]=a);b[2]&&(k[l="parms"]=b[2]);b[3]&&(k[l="state"]=b[3]);d&&e?(l=JSON.stringify(k),h+=".js",c=c[1]+"var resources="+l+";"+c[2]+c[3],c=c.replace(/\u00A9/g,
"&#xA9;"),l=h,g=null,k="data:application/javascript,",k=Ba("Firefox")?k+encodeURIComponent(c):k+encodeURI(c),l&&(g=document.createElement("a"),"string"!=typeof g.download&&(g=null)),g?(g.href=k,g.download=l,document.body.appendChild(g),g.click(),document.body.removeChild(g),c="Check your Downloads folder for "+l+"."):(window.open(k),c="Check your browser for a new window/tab containing the requested data"+(l?" ("+l+")":"")+"."),c+=', copy it to your web server as "'+h+'", and then add the following to your web page:\n\n',
c+='<div id="'+f+'"></div>\n',c+="...\n",c+='<script type="text/javascript" src="'+h+'">\x3c/script>\n',c+='<script type="text/javascript">embedPC("'+f+'","'+d+'","'+e+'");\x3c/script>\n\n',c+="The machine should appear where the <div> is located.",t(c)):t("Missing XML/XSL resources")}
window.savePC=function(a,b,c){var d=db("Computer",a),e=db("Debugger",a);if(d){var f=Ne(d,!0),h=d.S?JSON.stringify(d.S):null;b||(b="/versions/pcjs/1.21.7/pc"+(e?"-dbg":"")+".js");if(c&&c({state:f,Mb:h}))return!0;ma(b,null,!0,function(c,d,e){zf(c,d,e,[a,ba(b,!0),h,f])});return!0}t("Unable to identify machine '"+a+"'");return!1};})();
window.savePC=function(a,b,c){var d=$a("Computer",a),e=$a("Debugger",a);if(d){var f=Ve(d,!0),h=d.S?JSON.stringify(d.S):null;b||(b="/versions/pcjs/1.21.7/pc"+(e?"-dbg":"")+".js");if(c&&c({state:f,Ob:h}))return!0;ma(b,null,!0,function(c,d,e){Gf(c,d,e,[a,ba(b,!0),h,f])});return!0}t("Unable to identify machine '"+a+"'");return!1};})();

View file

@ -1,118 +1,123 @@
(function(){var m;function aa(a){var b=16,c;if(a){b||(b=16);if("$"==a.charAt(0))b=16,a=a.substr(1);else if("0x"==a.substr(0,2))b=16,a=a.substr(2);else{var d=a.charAt(a.length-1).toLowerCase();"h"==d?(b=16,d=null):"."==d&&(b=10,d=null);null==d&&(a=a.substr(0,a.length-1))}var e,d=a,f=b;(f&&10!=f?16==f?null!==d.match(/^[0-9a-f]+$/i):2==f&&null!==d.match(/^[01]+$/i):null!==d.match(/^[0-9]+$/))&&!isNaN(e=parseInt(a,b))&&(c=e|0)}return c}
function ba(a,b){var c="";void 0===b?b=8:8<b&&(b=8);if(null==a||isNaN(a))for(;0<b--;)c="?"+c;else for(;0<b--;){var d=a&15,d=d+(0<=d&&9>=d?48:55),c=String.fromCharCode(d)+c;a>>=4}return c}function ca(a,b){var c=a,d=a.lastIndexOf("/");0<=d&&(c=a.substr(d+1));d=c.indexOf("&");0<d&&(c=c.substr(0,d));b&&(d=c.lastIndexOf("."),0<d&&(c=c.substring(0,d)));return c}function da(a){var b="",c=a.lastIndexOf(".");0<=c&&(b=a.substr(c+1).toLowerCase());return b}
function ea(a,b){return-1!==a.indexOf(b,a.length-b.length)}var fa={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};function ga(a){return a.replace(/[&<>"']/g,function(a){return fa[a]})}var ha=Date.now||function(){return+new Date};function ia(){function a(a){return(10>a?"0":"")+a}var b=new Date;return b.getFullYear()+"-"+a(b.getMonth()+1)+"-"+a(b.getDate())+" "+a(b.getHours())+":"+a(b.getMinutes())+":"+a(b.getSeconds())}
function n(a,b,c,d){var e=0,f=null,h=null;if("object"==typeof resources&&(f=resources[a]))return d&&d(a,f,e),[f,e];if(c&&"function"==typeof resources)return resources(a,function(b,c){d&&d(a,b,c)}),h;var g=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");c&&(g.onreadystatechange=function(){4===g.readyState&&(f=g.responseText,200==g.status||!g.status&&f.length&&"file:"==(window?window.location.protocol:"file:")||(e=g.status||-1),d&&d(a,f,e))});if(b&&"object"==
typeof b){var k="",l;for(l in b)b.hasOwnProperty(l)&&(k&&(k+="&"),k+=l+"="+encodeURIComponent(b[l]));k=k.replace(/%20/g,"+");g.open("POST",a,!!c);g.setRequestHeader("Content-type","application/x-www-form-urlencoded");g.send(k)}else g.open("GET",a,!!c),"bytes"==b&&g.overrideMimeType("text/plain; charset=x-user-defined"),g.send();c||(f=g.responseText,200!=g.status&&(e=g.status||-1),d&&d(a,f,e),h=[f,e]);return h}function ja(){return"http://"+(window?window.location.host:"www.pcjs.org")}
function p(a){window&&window.alert(a)}function ka(a){var b=!1;window&&(b=window.confirm(a));return b}var la=null;function ma(){if(null==la){var a=!1;if(window)try{window.localStorage.setItem("PCjs.localStorage","PCjs.localStorage"),a="PCjs.localStorage"==window.localStorage.getItem("PCjs.localStorage"),window.localStorage.removeItem("PCjs.localStorage")}catch(b){a=!1}la=a}return la}function na(a){var b;if(window)try{b=window.localStorage.getItem(a)}catch(c){}return b}
function oa(a,b){try{return window.localStorage.setItem(a,b),!0}catch(c){}return!1}function pa(a){if(window){var b=window?window.navigator.userAgent:"";return"iOS"==a&&b.match(/(iPod|iPhone|iPad)/)&&b.match(/AppleWebKit/)||"MSIE"==a&&b.match(/(MSIE|Trident)/)||0<=b.indexOf(a)?!0:!1}return!1}var q={init:[],show:[],exit:[]},qa=!1,ra=!0;function sa(a,b){if(window){var c=window[a];window[a]="function"!==typeof c?b:function(){c&&c();b()}}}function ta(a){q.init.push(a)}
function ua(a){if(ra)try{for(var b=0;b<a.length;b++)a[b]()}catch(c){p("An unexpected exception occurred:\n\n"+c.message+"\n\nPlease send this information to support@pcjs.org. Thanks.")}}function va(a){!ra&&a?(ra=!0,qa&&wa("init")):ra=a}function wa(a){q[a]&&ua(q[a])}sa("onload",function(){qa=!0;ua(q.init)});sa("onpageshow",function(){ua(q.show)});sa(pa("Opera")||pa("iOS")?"onunload":"onbeforeunload",function(){ua(q.exit)});
function r(a,b,c){this.type=a;b||(b={id:"",name:""});this.id=b.id;this.name=b.name;this.La=b.comment;this.Wa=b;void 0===this.id&&(this.id="");b=this.id.indexOf(".");0<b?(this.Na=this.id.substr(0,b),this.Ma=this.id.substr(b+1)):this.Ma=this.id;this[a]=c;this.g={da:!1,la:!1,Fa:!1,H:!1,$:!1};this.za=null;this.g.$=!1;this.v={};this.J=null;t.push(this)}var xa=void 0,ya={};
if(window){xa||(xa=window.location.search.substr(1));for(var za,Aa=/\+/g,Ba=/([^&=]+)=?([^&]*)/g;za=Ba.exec(xa);)ya[decodeURIComponent(za[1].replace(Aa," "))]=decodeURIComponent(za[2].replace(Aa," "))}function Ca(a){function b(){}if(window){if(!a)throw new TypeError;if(Object.create)return Object.create(a);var c=typeof a;if("object"!==c&&"function"!==c)throw new TypeError;}b.prototype=a;return new b}
function u(a,b){b||(b=r);a.prototype=Ca(b.prototype);a.prototype.constructor=a;a.prototype.parent=b.prototype}var t=[],Da={};function Ea(a,b,c){Da[a]&&b&&(Da[a][b]=c)}function v(a){var b,c=[];a&&(a=0<(b=a.indexOf("."))?a.substr(0,b+1):"");for(b=0;b<t.length;b++){var d=t[b];a&&d.id.indexOf(a)||c.push(d)}return c}
function Fa(a,b){var c;if(void 0!==a){var d;b&&(b=0<(d=b.indexOf("."))?b.substr(0,d+1):"");for(d=0;d<t.length;d++)if(c)c==t[d]&&(c=null);else if(!(a!=t[d].type||b&&t[d].id.indexOf(b)))return t[d]}return null}function w(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")")}catch(c){p(c.message+" ("+a+")")}return b}
function Ga(a,b){for(var c=y(b.parentNode,"pc8080-control"),d=0;d<c.length;d++)for(var e=c[d].childNodes,f=0;f<e.length;f++){var h=e[f];if(1===h.nodeType){var g=h.getAttribute("class");if(g)for(var k=g.split(" "),l=0;l<k.length;l++)switch(g=k[l],g){case "pc8080-binding":(g=w(h))&&g.binding&&a.M(g.type,g.binding,h,g.value),l=k.length}}}}
function y(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a.getElementsByClassName(b);var d;c=[];a=a.getElementsByTagName("*");var e=new RegExp("(^| )"+b+"( |$)");b=0;for(d=a.length;b<d;b++)e.test(a[b].className)&&c.push(a[b]);return c}
r.prototype={constructor:r,parent:null,toString:function(){return this.name?this.name:this.id||this.type},M:function(a,b,c){switch(b){case "clear":return this.v[b]||(this.v[b]=c,c.onclick=function(a){return function(){a.v.print&&(a.v.print.value="")}}(this)),!0;case "print":return this.v[b]||(this.Ea=this.v[b]=c,c.value="",this.L=function(a){return function(b,c){8192<a.value.length&&(a.value=a.value.substr(a.value.length-4096));a.value+=(void 0!==c?c+": ":"")+(b||"")+"\n";a.scrollTop=a.scrollHeight}}(c),
this.I=function(a,b,c){this.L(a,"notice",c)}),!0;default:return!1}},log:function(){},L:function(){},status:function(a){this.L(this.Ma+": "+a)},I:function(a,b){b||p(a)},X:function(){return this.g.H=!0},W:function(a,b){b&&(this.g.H=!1);return!0}};function Ha(a,b){if(a.g.Fa)return a.g.la&&(a.g.la=!1),a.g.Fa=!1;if(a.g.$)return a.L(a.toString()+" error"),!1;a.g.la=b;return a.g.la}function z(a){if(!a.g.$&&(a.g.da=!0,a.g.da)){var b=a.za;a.za=null;b&&b()}}
function Ia(a,b){b&&(a.g.da?b():a.za=b);return a.g.da}
var Ja="undefined"!==typeof ArrayBuffer,Ka=[1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,
0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1];function La(a){r.call(this,"Panel",a,La)}u(La);m=La.prototype;m.M=function(a,b,c,d){return this.w&&this.w.M(a,b,c,d)||this.a&&this.a.M(a,b,c,d)||this.b&&this.b.M(a,b,c,d)?!0:this.parent.M.call(this,a,b,c,d)};m.ma=function(a,b,c,d){this.w=a;this.C=b;this.a=c;this.J=d;this.b=Ma(a,"Keyboard")};m.X=function(a,b){b||Na();return!0};m.W=function(){return!0};m.ca=function(){};
function Na(){for(var a=!1,b=y(document,"pc8080","panel"),c=0;c<b.length;c++){var d=b[c],e=w(d),f;a:{f=e.id;if(void 0!==f)for(var h=void 0,h=0;h<t.length;h++)if(t[h].id===f){f=t[h];break a}f=null}f||(a=!0,f=new La(e));Ga(f,d);a&&z(f)}}ta(Na);
function Oa(a,b,c){r.call(this,"Bus",a,Oa);this.a=b;this.J=c;this.f=a.buswidth||16;this.i=Math.pow(2,this.f);this.h=this.i-1|0;this.F=20>=this.f?12:24>=this.f?14:15;this.D=1<<this.F;this.j=this.D>>2;this.l=this.D-1;this.c=this.i/this.D|0;this.m=[];this.s=[];this.o=[];this.u=[];a=new A;Pa(a,this.J);this.b=Array(this.c);for(b=0;b<this.c;b++)this.b[b]=a;a=this.a;b=this.b;c=this.F;var d=this.h;a.K=b;a.F=c;a.D=1<<a.F;a.P=a.D-1;a.wa=b.length;a.ja=a.wa-1;a.Y=d;z(this)}u(Oa);Oa.prototype.reset=function(){};
Oa.prototype.X=function(a,b){b||this.reset();return!0};function Ra(a,b,c,d){for(var e=b>>>a.F;0<c&&e<a.b.length;){var f=a.b[e],h=e*a.D,g=c>a.D?a.D:c;if(f&&f.size){if(f.type==d){if(b+c<=f.ka)return f.Da+=f.ka-b,f.ka=b,!0;if(b>=f.ka+f.Da){g=f.size-(b-h);g>c&&(g=c);f.Da=b-f.ka+g;c-=g;b=h+a.D;continue}}return Sa(1,b,c)}f=a.b[e];b=new A(b,g,a.D,d);Pa(b,a.J,f);a.b[e++]=b;b=h+a.D;c-=g}return 0>=c?!0:Sa(2,b,c)}function Sa(a,b,c){p("Memory block error ("+a+": "+ba(b)+","+ba(c)+")");return!1}var Ta;
if(Ja){var Ua=new ArrayBuffer(2);(new DataView(Ua)).setUint16(0,256,!0);Ta=256===(new Uint16Array(Ua))[0]}else Ta=!1;var Va=Ta;
function A(a,b,c,d){this.id=Wa+=2;this.a=null;this.ka=a;this.Da=b;this.size=c||0;this.type=d||Xa;this.h=d==Ya;Pa(this);this.V=this.eb=!1;if(c)if(Ja)this.c=new ArrayBuffer(c),this.f=new DataView(this.c,0,c),this.b=new Uint8Array(this.c,0,c),this.l=new Uint16Array(this.c,0,c>>1),this.a=new Int32Array(this.c,0,c>>2),Za(this,Va?$a:ab);else{this.a=Array(c>>2);for(a=0;a<this.a.length;a++)this.a[a]=0;Za(this,bb)}else Za(this)}var Xa=0,Ya=2,Wa=0;
A.prototype={constructor:A,parent:null,save:function(){var a,b;if(Ja)for(a=Array(this.size>>2),b=0;b<a.length;b++)a[b]=this.f.getInt32(b<<2,!0);else a=this.a;return a},restore:function(a){if(a&&this.size==a.length<<2){var b;if(Ja)for(b=0;b<a.length;b++)this.f.setInt32(b<<2,a[b],!0);else this.a=a;return this.V=!0}return!1},m:function(){return 255},s:function(){},o:function(a,b){return this.ua(a++,b++)|this.ua(a,b)<<8},v:function(a,b,c){this.va(a++,b&255,c++);this.va(a,b>>8,c)},B:function(a){return this.a[a>>
2]>>>((a&3)<<3)&255},N:function(a){var b=a>>2;a=(a&3)<<3;var c=this.a[b]>>a;return 24>a?c&65535:c&255|(this.a[b+1]&255)<<8},T:function(a,b){var c=a>>2,d=(a&3)<<3;this.a[c]=this.a[c]&~(255<<d)|b<<d;this.V=!0},wa:function(a,b){var c=a>>2,d=(a&3)<<3;24>d?this.a[c]=this.a[c]&~(65535<<d)|b<<d:(this.a[c]=this.a[c]&16777215|b<<24,c++,this.a[c]=this.a[c]&-256|b>>8);this.V=!0},C:function(a,b){return this.w(a,b)},F:function(a,b){return this.G(a,b)},R:function(a,b,c){this.h||this.Za(a,b,c)},Y:function(a,b,c){this.h||
this.Z(a,b,c)},u:function(a){return this.b[a]},A:function(a){return this.b[a]},D:function(a){return this.f.getUint16(a,!0)},K:function(a){return a&1?this.b[a]|this.b[a+1]<<8:this.l[a>>1]},P:function(a,b){this.b[a]=b;this.V=!0},S:function(a,b){this.b[a]=b;this.V=!0},U:function(a,b){this.f.setUint16(a,b,!0);this.V=!0},ja:function(a,b){a&1?(this.b[a]=b,this.b[a+1]=b>>8):this.l[a>>1]=b;this.V=!0}};function Pa(a,b,c){a.J=b;a.i=a.j=0;c&&((a.i=c.i)&&cb(a,db,!1),(a.j=c.j)&&eb(a,db,!1))}
function eb(a,b,c){c&&a.j||(a.va=!a.h&&b[2]||a.s,a.ib=!a.h&&b[3]||a.v);if(c||void 0===c)a.Za=b[2]||a.s,a.Z=b[3]||a.v}function cb(a,b,c){c&&a.i||(a.ua=b[0]||a.m,a.gb=b[1]||a.o);if(c||void 0===c)a.w=b[0]||a.m,a.G=b[1]||a.o}function Za(a,b){b||(b=fb);cb(a,b,void 0);eb(a,b,void 0)}var fb=[],bb=[A.prototype.B,A.prototype.N,A.prototype.T,A.prototype.wa],db=[A.prototype.C,A.prototype.F,A.prototype.R,A.prototype.Y];
if(Ja)var ab=[A.prototype.u,A.prototype.D,A.prototype.P,A.prototype.U],$a=[A.prototype.A,A.prototype.K,A.prototype.S,A.prototype.ja];
function gb(a,b){r.call(this,"CPU",a,gb);var c=a.cycles||b,d=a.multiplier||1;this.c={};this.c.ia=c;this.c.ha=d;this.c.Ga=Math.round(this.c.ia/1E4)/100;this.c.ea=this.c.Ga*this.c.ha;this.g.O=!1;this.g.Ra=!1;this.g.Pa=a.autoStart;this.g.Qa=!1;this.g.xa=!1;this.c.Ba=this.c.ga=0;this.c.Ca=a.csStart;this.c.na=a.csInterval;this.c.oa=a.csStop;this.bb=this.Ja.bind(this);z(this)}u(gb);var hb=["power","reset"];m=gb.prototype;
m.ma=function(a,b,c,d){this.w=a;this.C=b;this.J=d;for(b=0;b<hb.length;b++)(c=this.v[hb[b]])&&this.w.M(null,hb[b],c);Ma(a,"FPU");this.G=Ma(a,"ChipSet");a=ib(a,"autoStart");null!=a&&(this.g.Pa="true"==a?!0:"false"==a?!1:!!a);z(this)};m.reset=function(){};m.save=function(){return null};m.restore=function(){return!1};m.X=function(a,b){if(!b){if(a&&this.restore){jb(this);if(!this.restore(a))return!1;kb(this)}else this.reset();this.L("No debugger detected")}lb(this);return!0};
m.W=function(a){return a?this.save():!0};function mb(a){(a.g.Pa||void 0===a.v.run)&&a.Ja()}m.Sa=function(){return 0};function kb(a){void 0===a.c.Ca&&(a.c.Ca=0);void 0===a.c.na&&(a.c.na=-1);void 0===a.c.oa&&(a.c.oa=-1);a.g.xa=0<=a.c.Ca&&0<a.c.na;a.g.xa&&(a.c.Ba=0,a.c.ga=a.c.Ca-a.S)}
m.M=function(a,b,c){var d=this;a=!1;switch(b){case "power":case "reset":this.v[b]=c;a=!0;break;case "run":this.v[b]=c;c.onclick=function(){var a;if(a=d.w)if(a=d.w,a.g.H)a=!0;else{var b=null,c,g=v(a.id);for(c=0;c<g.length&&(b=g[c],b===a||b.g.da);c++);if(c==g.length)for(c=0;c<g.length&&(b=g[c],b===a||b.g.H);c++);c==g.length&&(b=a);p("The "+b.type+" component ("+b.id+") is not "+(b.g.da?"powered yet":"ready yet"+(b.za?" (waiting for notification)":""))+".");a=!1}a&&(d.g.O?nb(d,!0):d.Ja())};a=!0;break;
case "speed":this.v[b]=c;a=!0;break;case "setSpeed":this.v[b]=c,c.onclick=function(){ob(d,d.c.ha<<1)},c.textContent=this.c.ea.toFixed(2)+"Mhz",a=!0}return a};function pb(a,b,c){a.S+=b;c&&(a.R=a.a=0)}function qb(a,b){var c=30;60>c&&(c=60);2>c&&(c=2);var d=1;b&&1<a.c.ha&&a.c.aa&&(d=a.c.aa/a.c.Ga);a.c.Ta=Math.round(1E3/30);a.c.fb=Math.floor(a.c.ia/c*d);a.c.Ha=Math.floor(a.c.ia/30*d);a.c.Va=Math.floor(a.c.ia/60*d);a.c.Ua=Math.floor(a.c.ia/2*d);b||(a.c.ra=a.c.Ha,a.c.qa=a.c.Va,a.c.pa=a.c.Ua);a.c.Ia=0}
function rb(a){return a.S+a.N+a.R-a.a}function jb(a){a.c.aa=0;a.S=a.N=a.R=a.a=0;kb(a);ob(a,1)}function ob(a,b){if(void 0!==b){.8>a.c.aa/a.c.ea&&(b=1);a.c.ha=b;var c=a.c.Ga*a.c.ha;if(a.c.ea!=c){a.c.ea=c;var c=a.c.ea.toFixed(2)+"Mhz",d=a.v.setSpeed;d&&(d.textContent=c);a.L("target speed: "+c)}}pb(a,a.N);a.N=0;a.c.fa=ha();a.c.ba=0;qb(a)}
m.Ja=function(){if(Ha(this,!0)){if(!this.g.O){ob(this);this.w&&this.w.start(this.c.fa,rb(this));this.g.O=!0;this.g.Ra=!0;this.G&&this.G.hb();var a=this.v.run;a&&(a.textContent="Halt");this.w&&this.w.ca(!0)}this.c.Ia>=this.c.ia&&qb(this,!0);this.c.sa=0;this.c.Aa=ha();this.c.ba&&(a=this.c.Aa-this.c.ba,a>this.c.Ta&&(this.c.fa+=a,this.c.fa>this.c.Aa&&(this.c.fa=this.c.Aa)));try{do{var b=this.g.xa?1:this.c.fb;this.G&&(this.G.Ya(),b=this.G.kb(0,b),b=this.G.jb(b));try{this.Xa(b)}catch(e){if("number"!=typeof e)throw e;
}var c=this.R-this.a;this.N+=c;this.c.sa+=c;pb(this,0,!0);a=c;if(this.g.xa){var d=!1;this.c.Ba=this.c.Ba+this.Sa()|0;this.c.ga-=a;0>=this.c.ga&&(this.c.ga+=this.c.na,d=!0);0<=this.c.oa&&this.c.oa<=rb(this)&&(this.c.na=this.c.oa=-1,kb(this),nb(this),d=!0);d&&this.L(rb(this)+" cycles: checksum="+ba(this.c.Ba))}this.c.qa-=c;0>=this.c.qa&&(this.c.qa+=this.c.Va);this.c.pa-=c;0>=this.c.pa&&(this.c.pa+=this.c.Ua,this.w&&this.w.ca());this.c.ra-=c;if(0>=this.c.ra){this.c.ra+=this.c.Ha;break}}while(this.g.O)}catch(e){nb(this);
lb(this);this.w&&this.w.stop(ha(),rb(this));Ha(this,!1);b=e.stack||e.message;this.g.$=!0;this.I(b);return}b=setTimeout;c=this.bb;this.c.ba=ha();a=this.c.Ta;this.c.sa&&(a=Math.round(a*this.c.sa/this.c.Ha));a-=this.c.ba-this.c.Aa;if(d=this.c.ba-this.c.fa)this.c.aa=Math.round(this.N/(10*d))/100,864E5<=d&&(this.S=0,this.G&&this.G.Ya(!0),ob(this));if(0>a||this.c.aa<this.c.ea)a=0;this.c.Ia+=this.c.sa;this.c.ba+=a;b(c,a)}else lb(this),this.w&&this.w.stop(ha(),rb(this))};m.Xa=function(){return 0};
function nb(a,b){a.g.la&&(a.g.Fa=!0);a.R-=a.a;a.a=0;pb(a,a.N);a.N=0;if(a.g.O){a.g.O=!1;a.G&&a.G.hb();var c=a.v.run;c&&(c.textContent="Run")}a.g.ya=b}function lb(a){a.w&&a.w.ca(void 0)}function sb(a){this.ab=a.model||8080;gb.call(this,a,1E6);this.$a=tb;jb(this);this.g.ya=this.g.cb=!1;this.Ka=0;this.K=[];this.F=this.D=this.P=this.wa=this.ja=this.Y=0;ub(this)}u(sb,gb);m=sb.prototype;m.reset=function(){this.g.O&&nb(this);ub(this);jb(this);this.g.$=!1};
function ub(a){a.b=0;a.h=0;a.i=0;a.j=0;a.l=0;a.m=0;a.o=0;a.A=0;B(a,0);vb(a,0);a.U=0}m.Sa=function(){var a=this.b+this.h+this.i+this.j+this.l+this.m+this.o|0;return a=a+this.A+this.u+wb(this)|0};
m.save=function(){var a=new C(this);D(a,0,[this.b,this.h,this.i,this.j,this.l,this.m,this.o,this.A,this.u,wb(this)]);D(a,1,[this.Z,this.U,this.S,this.c.ha]);for(var b=this.C,c=0,d=[],e=0;e<b.c;e++){var f=b.b[e];if(f.V||f.eb){d[c++]=e;var h=c++;a:if(f=f.save()){for(var g=0,k=0,l=[];g<f.length;){for(var H=f[g],x=g+1;x<f.length&&f[x]===H;)x++;l[k++]=x-g;l[k++]=H;g=x}if(l.length<f.length){f=l;break a}}d[h]=f}}D(a,2,d);return a.data()};
m.restore=function(a){var b=a[0];this.b=b[0];this.h=b[1];this.i=b[2];this.j=b[3];this.l=b[4];this.m=b[5];this.o=b[6];this.A=b[7]&65535;B(this,b[8]);vb(this,b[9]);b=a[1];this.Z=b[0];this.U=b[1];this.S=b[2];ob(this,b[3]);a:{b=this.C;a=a[2];var c;for(c=0;c<a.length-1;c+=2){var d=a[c],e=a[c+1];if(e&&e.length<b.j){for(var f=0,h=Array(b.j),g=0;g<e.length-1;)for(var k=e[g++],l=e[g++];k--;)h[f++]=l;e=h}f=b.b[d];if(!f||!f.restore(e)){p("Unable to restore memory block "+d);b=!1;break a}}b=!0}return b};
m.M=function(a,b,c){var d=!1;switch(b){case "A":case "B":case "C":case "D":case "E":case "H":case "L":case "SP":case "PC":case "F":case "SF":case "ZF":case "AF":case "PF":case "CF":this.v[b]=c;this.Ka++;d=!0;break;default:d=this.parent.M.call(this,a,b,c)}return d};function xb(a){return a.h<<8|a.i}function yb(a,b){a.h=b>>8&255;a.i=b&255}function zb(a){return a.j<<8|a.l}function Ab(a,b){a.j=b>>8&255;a.l=b&255}function E(a){return a.m<<8|a.o}function F(a,b){a.m=b>>8&255;a.o=b&255}
function B(a,b){a.u=b&65535}function G(a){return a.f&256?1:0}function Bb(a){return Ka[a.s&255]?4:0}function wb(a){return a.T&-214|(a.s&128?128:0)|(a.f&255?0:64)|((a.s^a.B)&16?16:0)|Bb(a)|G(a)}function vb(a,b){a.f=a.s=a.B=0;b&1&&(a.f|=256);b&4||(a.s|=1);b&16&&(a.B|=16);b&64||(a.f|=255);b&128&&(a.s^=192);a.T=a.T&-513|b&512|2}function I(a,b){a.B=a.b^b;return(a.f=a.s=a.b+b)&255}function J(a,b){a.B=a.b^b;return(a.f=a.s=a.b+b+(a.f&256?1:0))&255}function K(a,b){return a.f=a.s=a.B=a.b&b}
function L(a,b){a.B=a.b^b;a.f=a.s=a.b-b}function M(a,b){a.B=b;b=(a.s=b-1)&255;a.f=a.f&-256|b;return b}function N(a,b){a.B=b;b=(a.s=b+1)&255;a.f=a.f&-256|b;return b}function O(a,b){return a.f=a.s=a.B=a.b|b}function P(a,b){a.B=a.b^b;return(a.f=a.s=a.b-b)&255}function Q(a,b){a.B=a.b^b;return(a.f=a.s=a.b-b-(a.f&256?1:0))&255}function R(a,b){return a.f=a.s=a.B=a.b^b}function S(a,b){return a.K[(b&a.Y)>>>a.F].ua(b&a.P,b)}
function Cb(a,b){var c=b&a.P,d=(b&a.Y)>>>a.F;if(c<a.P)return a.K[d].gb(c,b);c=a.K[d].ua(c,b);return c|=a.K[d+1&a.ja].ua(0,b+1)<<8}function T(a,b,c){a.K[(b&a.Y)>>>a.F].va(b&a.P,c&255,b)}function Db(a,b,c){var d=b&a.P,e=(b&a.Y)>>>a.F;d<a.P?a.K[e].ib(d,c&65535,b):(a.K[e++].va(d,c&255,b),a.K[e&a.ja].va(0,c>>8&255,b+1))}function U(a){var b=S(a,a.u);B(a,a.u+1);return b}function V(a){var b=Cb(a,a.u);B(a,a.u+2);return b}function W(a){var b=Cb(a,a.A);a.A=a.A+2&65535;return b}
function X(a,b){a.A=a.A-2&65535;Db(a,a.A,b)}function Y(a,b,c,d){d=d||2;a.v[b]&&(void 0===c&&(a.g.$=!0,a.I("Value for "+b+" is invalid"),nb(a)),c=!a.g.O||a.g.Qa?ba(c,d):"--------".substr(0,d),a.v[b].textContent!=c&&(a.v[b].textContent=c))}
m.ca=function(a){this.Ka&&(a||!this.g.O||this.g.Qa)&&(Y(this,"A",this.b),Y(this,"B",this.h),Y(this,"C",this.i),Y(this,"D",this.j),Y(this,"E",this.l),Y(this,"H",this.m),Y(this,"L",this.o),Y(this,"SP",this.A,4),Y(this,"PC",this.u,4),a=wb(this),Y(this,"F",a,2),Y(this,"SF",a&128,1),Y(this,"ZF",a&64,1),Y(this,"AF",a&16,1),Y(this,"PF",a&4,1),Y(this,"CF",a&1,1));if(a=this.v.speed)a.textContent=this.g.O&&this.c.aa?this.c.aa.toFixed(2)+"Mhz":"Stopped"};
m.Xa=function(a){this.g.ya=!0;this.g.cb=!1;this.g.Ra=!1;this.R=this.a=a;this.G&&!a&&this.G.Ya();a||(this.Z|=4);do{if(this.U&&this.U&4){this.Z=this.a=0;break}this.Z=0;this.$a[U(this)].call(this)}while(0<this.a);return this.g.ya?this.R-this.a:void 0===this.g.ya?0:-1};ta(function(){for(var a=y(document,"pc8080","cpu"),b=0;b<a.length;b++){var c=a[b],d=w(c),d=new sb(d);Ga(d,c)}});function Eb(){this.a-=4}function Fb(){B(this,V(this));this.a-=10}function Gb(){B(this,W(this));this.a-=10}
function Hb(){var a=V(this);X(this,this.u);B(this,a);this.a-=17}
var tb=[Eb,function(){yb(this,V(this));this.a-=10},function(){T(this,xb(this),this.b);this.a-=7},function(){yb(this,xb(this)+1);this.a-=5},function(){this.h=N(this,this.h);this.a-=5},function(){this.h=M(this,this.h);this.a-=5},function(){this.h=U(this);this.a-=7},function(){var a=this.b<<1;this.b=a&255|a>>8;this.f=this.f&255|a&256;this.a-=4},Eb,function(){var a;F(this,a=E(this)+xb(this));this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=S(this,xb(this));this.a-=7},function(){yb(this,xb(this)-
1);this.a-=5},function(){this.i=N(this,this.i);this.a-=5},function(){this.i=M(this,this.i);this.a-=5},function(){this.i=U(this);this.a-=7},function(){var a=this.b<<8&256;this.b=(a|this.b)>>1;this.f=this.f&255|a;this.a-=4},Eb,function(){Ab(this,V(this));this.a-=10},function(){T(this,zb(this),this.b);this.a-=7},function(){Ab(this,zb(this)+1);this.a-=5},function(){this.j=N(this,this.j);this.a-=5},function(){this.j=M(this,this.j);this.a-=5},function(){this.j=U(this);this.a-=7},function(){var a=this.b<<
1;this.b=a&255|this.f>>8;this.f=this.f&255|a&256;this.a-=4},Eb,function(){var a;F(this,a=E(this)+zb(this));this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=S(this,zb(this));this.a-=7},function(){Ab(this,zb(this)-1);this.a-=5},function(){this.l=N(this,this.l);this.a-=5},function(){this.l=M(this,this.l);this.a-=5},function(){this.l=U(this);this.a-=7},function(){var a=this.b<<8&256;this.b=(this.f&256|this.b)>>1;this.f=this.f&255|a;this.a-=4},Eb,function(){F(this,V(this));this.a-=10},function(){Db(this,
V(this),E(this));this.a-=16},function(){F(this,E(this)+1);this.a-=5},function(){this.m=N(this,this.m);this.a-=5},function(){this.m=M(this,this.m);this.a-=5},function(){this.m=U(this);this.a-=7},function(){var a=this.b,b=!!G(this),c=!!((this.s^this.B)&16);9<(a&15)||c?(a+=6,c=!0):c=!1;160<=a||b?(a+=96,b=!0):b=!1;this.f=this.s=this.b=a&255;this.f=b?this.f|256:this.f&-257;this.B=c?~this.s&16|this.B&-17:this.s&16|this.B&-17;this.a-=4},Eb,function(){var a;F(this,a=E(this)+E(this));this.f=this.f&255|a>>
8&256;this.a-=10},function(){F(this,Cb(this,V(this)));this.a-=16},function(){F(this,E(this)-1);this.a-=5},function(){this.o=N(this,this.o);this.a-=5},function(){this.o=M(this,this.o);this.a-=5},function(){this.o=U(this);this.a-=7},function(){this.b=~this.b&255;this.a-=4},Eb,function(){this.A=V(this)&65535;this.a-=10},function(){T(this,V(this),this.b);this.a-=13},function(){this.A=this.A+1&65535;this.a-=5},function(){var a=E(this);T(this,a,N(this,S(this,a)));this.a-=10},function(){var a=E(this);T(this,
a,M(this,S(this,a)));this.a-=10},function(){T(this,E(this),U(this));this.a-=10},function(){this.f|=256;this.a-=4},Eb,function(){var a;this.A=(a=E(this)+this.A)&65535;this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=S(this,V(this));this.a-=13},function(){this.A=this.A-1&65535;this.a-=5},function(){this.b=N(this,this.b);this.a-=5},function(){this.b=M(this,this.b);this.a-=5},function(){this.b=U(this);this.a-=7},function(){this.f=G(this)?this.f&-257:this.f|256;this.a-=4},function(){this.a-=5},
function(){this.h=this.i;this.a-=5},function(){this.h=this.j;this.a-=5},function(){this.h=this.l;this.a-=5},function(){this.h=this.m;this.a-=5},function(){this.h=this.o;this.a-=5},function(){this.h=S(this,E(this));this.a-=7},function(){this.h=this.b;this.a-=5},function(){this.i=this.h;this.a-=5},function(){this.a-=5},function(){this.i=this.j;this.a-=5},function(){this.i=this.l;this.a-=5},function(){this.i=this.m;this.a-=5},function(){this.i=this.o;this.a-=5},function(){this.i=S(this,E(this));this.a-=
7},function(){this.i=this.b;this.a-=5},function(){this.j=this.h;this.a-=5},function(){this.j=this.i;this.a-=5},function(){this.a-=5},function(){this.j=this.l;this.a-=5},function(){this.j=this.m;this.a-=5},function(){this.j=this.o;this.a-=5},function(){this.j=S(this,E(this));this.a-=7},function(){this.j=this.b;this.a-=5},function(){this.l=this.h;this.a-=5},function(){this.l=this.i;this.a-=5},function(){this.l=this.j;this.a-=5},function(){this.a-=5},function(){this.l=this.m;this.a-=5},function(){this.l=
this.o;this.a-=5},function(){this.l=S(this,E(this));this.a-=7},function(){this.l=this.b;this.a-=5},function(){this.m=this.h;this.a-=5},function(){this.m=this.i;this.a-=5},function(){this.m=this.j;this.a-=5},function(){this.m=this.l;this.a-=5},function(){this.a-=5},function(){this.m=this.o;this.a-=5},function(){this.m=S(this,E(this));this.a-=7},function(){this.m=this.b;this.a-=5},function(){this.o=this.h;this.a-=5},function(){this.o=this.i;this.a-=5},function(){this.o=this.j;this.a-=5},function(){this.o=
this.l;this.a-=5},function(){this.o=this.m;this.a-=5},function(){this.a-=5},function(){this.o=S(this,E(this));this.a-=7},function(){this.o=this.b;this.a-=5},function(){T(this,E(this),this.h);this.a-=7},function(){T(this,E(this),this.i);this.a-=7},function(){T(this,E(this),this.j);this.a-=7},function(){T(this,E(this),this.l);this.a-=7},function(){T(this,E(this),this.m);this.a-=7},function(){T(this,E(this),this.o);this.a-=7},function(){this.U|=4;this.a-=7;this.T&512||nb(this)},function(){T(this,E(this),
this.b);this.a-=7},function(){this.b=this.h;this.a-=5},function(){this.b=this.i;this.a-=5},function(){this.b=this.j;this.a-=5},function(){this.b=this.l;this.a-=5},function(){this.b=this.m;this.a-=5},function(){this.b=this.o;this.a-=5},function(){this.b=S(this,E(this));this.a-=7},function(){this.a-=5},function(){this.b=I(this,this.h);this.a-=4},function(){this.b=I(this,this.i);this.a-=4},function(){this.b=I(this,this.j);this.a-=4},function(){this.b=I(this,this.l);this.a-=4},function(){this.b=I(this,
this.m);this.a-=4},function(){this.b=I(this,this.o);this.a-=4},function(){this.b=I(this,S(this,E(this)));this.a-=7},function(){this.b=I(this,this.b);this.a-=4},function(){this.b=J(this,this.h);this.a-=4},function(){this.b=J(this,this.i);this.a-=4},function(){this.b=J(this,this.j);this.a-=4},function(){this.b=J(this,this.l);this.a-=4},function(){this.b=J(this,this.m);this.a-=4},function(){this.b=J(this,this.o);this.a-=4},function(){this.b=J(this,S(this,E(this)));this.a-=7},function(){this.b=J(this,
this.b);this.a-=4},function(){this.b=P(this,this.h);this.a-=4},function(){this.b=P(this,this.i);this.a-=4},function(){this.b=P(this,this.j);this.a-=4},function(){this.b=P(this,this.l);this.a-=4},function(){this.b=P(this,this.m);this.a-=4},function(){this.b=P(this,this.o);this.a-=4},function(){this.b=P(this,S(this,E(this)));this.a-=7},function(){this.b=P(this,this.b);this.a-=4},function(){this.b=Q(this,this.h);this.a-=4},function(){this.b=Q(this,this.i);this.a-=4},function(){this.b=Q(this,this.j);
this.a-=4},function(){this.b=Q(this,this.l);this.a-=4},function(){this.b=Q(this,this.m);this.a-=4},function(){this.b=Q(this,this.o);this.a-=4},function(){this.b=Q(this,S(this,E(this)));this.a-=7},function(){this.b=Q(this,this.b);this.a-=4},function(){this.b=K(this,this.h);this.a-=4},function(){this.b=K(this,this.i);this.a-=4},function(){this.b=K(this,this.j);this.a-=4},function(){this.b=K(this,this.l);this.a-=4},function(){this.b=K(this,this.m);this.a-=4},function(){this.b=K(this,this.o);this.a-=
4},function(){this.b=K(this,S(this,E(this)));this.a-=7},function(){this.b=K(this,this.b);this.a-=4},function(){this.b=R(this,this.h);this.a-=4},function(){this.b=R(this,this.i);this.a-=4},function(){this.b=R(this,this.j);this.a-=4},function(){this.b=R(this,this.l);this.a-=4},function(){this.b=R(this,this.m);this.a-=4},function(){this.b=R(this,this.o);this.a-=4},function(){this.b=R(this,S(this,E(this)));this.a-=7},function(){this.b=R(this,this.b);this.a-=4},function(){this.b=O(this,this.h);this.a-=
4},function(){this.b=O(this,this.i);this.a-=4},function(){this.b=O(this,this.j);this.a-=4},function(){this.b=O(this,this.l);this.a-=4},function(){this.b=O(this,this.m);this.a-=4},function(){this.b=O(this,this.o);this.a-=4},function(){this.b=O(this,S(this,E(this)));this.a-=7},function(){this.b=O(this,this.b);this.a-=4},function(){L(this,this.h);this.a-=4},function(){L(this,this.i);this.a-=4},function(){L(this,this.j);this.a-=4},function(){L(this,this.l);this.a-=4},function(){L(this,this.m);this.a-=
4},function(){L(this,this.o);this.a-=4},function(){L(this,S(this,E(this)));this.a-=7},function(){L(this,this.b);this.a-=4},function(){this.f&255&&(B(this,W(this)),this.a-=6);this.a-=5},function(){yb(this,W(this));this.a-=10},function(){var a=V(this);this.f&255&&B(this,a);this.a-=10},Fb,function(){var a=V(this);this.f&255&&(X(this,this.u),B(this,a),this.a-=6);this.a-=11},function(){X(this,xb(this));this.a-=11},function(){this.b=I(this,U(this));this.a-=7},function(){X(this,this.u);B(this,0);this.a-=
11},function(){this.f&255||(B(this,W(this)),this.a-=6);this.a-=5},Gb,function(){var a=V(this);this.f&255||B(this,a);this.a-=10},Fb,function(){var a=V(this);this.f&255||(X(this,this.u),B(this,a),this.a-=6);this.a-=11},Hb,function(){this.b=J(this,U(this));this.a-=7},function(){X(this,this.u);B(this,8);this.a-=11},function(){G(this)||(B(this,W(this)),this.a-=6);this.a-=5},function(){Ab(this,W(this));this.a-=10},function(){var a=V(this);G(this)||B(this,a);this.a-=10},function(){for(var a=U(this),b=this.C,
c=this.b,d=1,e=0;0<d;){var f=b.s[a],h=b.u[a]||1,g=1==h?255:2==h?65535:-1,g=(c>>>=e)&g;if(void 0!==f&&f[0])f[0](a,g,void 0);e+=h<<3;a+=h;d-=h}this.a-=10},function(){var a=V(this);G(this)||(X(this,this.u),B(this,a),this.a-=6);this.a-=11},function(){X(this,zb(this));this.a-=11},function(){this.b=P(this,U(this));this.a-=7},function(){X(this,this.u);B(this,16);this.a-=11},function(){G(this)&&(B(this,W(this)),this.a-=6);this.a-=5},Gb,function(){var a=V(this);G(this)&&B(this,a);this.a-=10},function(){for(var a=
U(this),b=this.C,c=1,d=0,e=0;0<c;){var f=b.m[a],h=b.o[a]||1,g=1==h?255:2==h?65535:-1,k=g;void 0!==f&&f[0]&&(k=f[0](a,void 0),void 0===k?k=g:k&=g);d|=k<<e;e+=h<<3;a+=h;c-=h}this.b=d&255;this.a-=10},function(){var a=V(this);G(this)&&(X(this,this.u),B(this,a),this.a-=6);this.a-=11},Hb,function(){this.b=Q(this,U(this));this.a-=7},function(){X(this,this.u);B(this,24);this.a-=11},function(){Bb(this)||(B(this,W(this)),this.a-=6);this.a-=5},function(){F(this,W(this));this.a-=10},function(){var a=V(this);
Bb(this)||B(this,a);this.a-=10},function(){var a=W(this);X(this,E(this));F(this,a);this.a-=18},function(){var a=V(this);Bb(this)||(X(this,this.u),B(this,a),this.a-=6);this.a-=11},function(){X(this,E(this));this.a-=11},function(){this.b=K(this,U(this));this.a-=7},function(){X(this,this.u);B(this,32);this.a-=11},function(){Bb(this)&&(B(this,W(this)),this.a-=6);this.a-=5},function(){B(this,E(this));this.a-=5},function(){var a=V(this);Bb(this)&&B(this,a);this.a-=10},function(){var a=E(this);F(this,zb(this));
Ab(this,a);this.a-=5},function(){var a=V(this);Bb(this)&&(X(this,this.u),B(this,a),this.a-=6);this.a-=11},Hb,function(){this.b=R(this,U(this));this.a-=7},function(){X(this,this.u);B(this,40);this.a-=11},function(){this.s&128||(B(this,W(this)),this.a-=6);this.a-=5},function(){var a=W(this);vb(this,a);this.b=a>>8;this.a-=10},function(){var a=V(this);this.s&128||B(this,a);this.a-=10},function(){this.T&=-513;this.a-=4},function(){var a=V(this);this.s&128||(X(this,this.u),B(this,a),this.a-=6);this.a-=
11},function(){X(this,wb(this)|this.b<<8);this.a-=11},function(){this.b=O(this,U(this));this.a-=7},function(){X(this,this.u);B(this,48);this.a-=11},function(){this.s&128&&(B(this,W(this)),this.a-=6);this.a-=5},function(){this.A=E(this)&65535;this.a-=5},function(){var a=V(this);this.s&128&&B(this,a);this.a-=10},function(){this.T|=512;this.a-=4},function(){var a=V(this);this.s&128&&(X(this,this.u),B(this,a),this.a-=6);this.a-=11},Hb,function(){L(this,U(this));this.a-=7},function(){X(this,this.u);B(this,
56);this.a-=11}];function Ib(a){r.call(this,"ROM",a,Ib);this.b=null;this.j=a.addr;this.c=a.size;this.f=a.alias;this.h=a.file;this.l=ca(this.h);if(this.h){a=this.h;var b=da(this.l);"json"!=b&&"hex"!=b&&(a=ja()+"/api/v1/dump?file="+this.h+"&format=bytes&decimal=true");var c=this;n(a,null,!0,function(a,b,f){Jb(c,a,b,f)})}}u(Ib);Ib.prototype.ma=function(a,b,c,d){this.C=b;this.a=c;this.J=d;Kb(this)};Ib.prototype.X=function(){this.i&&(this.J&&this.J.a(this.id,this.j,this.c,this.i),delete this.i);return!0};
Ib.prototype.W=function(){return!0};
function Jb(a,b,c,d){if(d)a.I("Unable to load system ROM (error "+d+": "+b+")");else{Ea(a.Na,b,c);if("["==c.charAt(0)||"{"==c.charAt(0))try{var e=eval("("+c+")"),f=e.bytes,h=e.data;if(f)a.b=f;else if(h)for(a.b=Array(4*h.length),d=c=0;c<h.length;c++)a.b[d++]=h[c]&255,a.b[d++]=h[c]>>8&255,a.b[d++]=h[c]>>16&255,a.b[d++]=h[c]>>24&255;else a.b=e;a.i=e.symbols;if(!a.b.length){p("Empty ROM: "+b);return}if(1==a.b.length){p(a.b[0]);return}}catch(g){a.I("ROM data error: "+g.message);return}else for(b=c.replace(/\n/gm,
" ").replace(/ +$/,"").split(" "),a.b=Array(b.length),e=0;e<b.length;e++)a.b[e]=aa(b[e]);Kb(a)}}
function Kb(a){if(!Ia(a))if(!a.h)z(a);else if(a.b&&a.C){if(a.b.length!=a.c){var b="ROM size (0x"+ba(a.b.length)+") does not match specified size ("+("0x"+ba(a.c))+")";a.g.$=!0;a.I(b)}else{b=a.j;if(Ra(a.C,b,a.c,Ya)){for(var c=0;c<a.b.length;c++){var d=a.C,e=b+c;d.b[(e&d.h)>>>d.F].Za(e&d.l,a.b[c]&255,e)}b=!0}else b=!1;if(b){b=[];"number"==typeof a.f?b.push(a.f):null!=a.f&&a.f.length&&(b=a.f);for(c=0;c<b.length;c++){for(var f=a,d=b[c],e=f.C,h=f.c,g=[],k=f.j>>>e.F;0<h&&k<e.b.length;)g.push(e.b[k++]),
h-=e.D;e=f.C;f=f.c;h=0;for(d>>>=e.F;0<f&&d<e.b.length;){k=g[h++];if(!k)break;e.b[d++]=k;f-=e.D}}delete a.b}}z(a)}}ta(function(){for(var a=y(document,"pc8080","rom"),b=0;b<a.length;b++){var c=a[b],d=w(c),d=new Ib(d);Ga(d,c)}});function Lb(a){r.call(this,"RAM",a,Lb);this.f=a.addr;this.c=a.size;this.b=!1}u(Lb);m=Lb.prototype;m.ma=function(a,b,c,d){this.C=b;this.a=c;this.J=d;z(this)};m.X=function(a,b){b||this.reset();return!0};m.W=function(a){return a?this.save():!0};
m.reset=function(){!this.b&&this.c&&Ra(this.C,this.f,this.c,1)&&(this.b=!0,this.status(Math.floor(this.c/1024)+"Kb allocated"));this.b||p("No RAM allocated")};m.save=function(){return null};m.restore=function(){return!0};ta(function(){for(var a=y(document,"pc8080","ram"),b=0;b<a.length;b++){var c=a[b],d=w(c),d=new Lb(d);Ga(d,c)}});function Mb(a){r.call(this,"Keyboard",a,Mb);z(this)}u(Mb);
ta(function(){for(var a=y(document,"pc8080","keyboard"),b=0;b<a.length;b++){var c=a[b],d=w(c),d=new Mb(d);Ga(d,c)}});function Nb(a){r.call(this,"Video",a,Nb);z(this)}u(Nb);
ta(function(){for(var a=y(document,"pc8080","video"),b=0;b<a.length;b++){var c=a[b],d=w(c),e=document.createElement("canvas");if(void 0===e||!e.getContext){c.innerHTML="<br/>Missing &lt;canvas&gt; support. Please try a newer web browser.";break}e.setAttribute("class","pcjs-canvas");e.setAttribute("width",d.screenWidth);e.setAttribute("height",d.screenHeight);e.style.backgroundColor=d.screenColor;e.style.height="auto";0<=(window?window.navigator.userAgent:"").indexOf("MSIE")&&(c.onresize=function(a,
b,c,d){return function(){b.style.height=(a.clientWidth*d/c|0)+"px"}}(c,e,d.screenWidth,d.screenHeight),c.onresize());var f=+(d.aspect||ya.aspect);f&&.3<=f&&3.33>=f&&(sa("onresize",function(a,b,c){return function(){b.style.height=(a.clientWidth/c|0)+"px"}}(c,e,f)),window.onresize());c.appendChild(e);f=document.createElement("textarea");pa("iOS")&&(f.setAttribute("autocapitalize","off"),f.setAttribute("autocorrect","off"));c.appendChild(f);e.getContext("2d");d=new Nb(d);Ga(d,c)}});
function C(a,b,c){this.id=a.id;this.key=Ob(a,b,c);this.J=a.J;Pb(this,a.Wa)}function Ob(a,b,c){a=a.id;if(b){var d=b.indexOf(".");0<d&&(a+=".v"+b.substr(0,d))}c&&(a+="."+c);return a}
C.prototype={constructor:C,value:function(){return this[this.id]},data:function(){return this[this.id]},toString:function(){var a=this[this.id];return"string"==typeof a?a:JSON.stringify(a)},clear:function(a){Pb(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(e){}for(c=0;c<b.length;c++)if((d=b[c])&&(a||d.substr(0,this.key.length)==this.key)){try{window.localStorage.removeItem(d)}catch(e){}b.splice(c,1);c=0}}};
function Pb(a,b){a[a.id]={};b&&D(a,"parms",b);a.a=!1}function Qb(a){var b=!0;if(ma()){var c=JSON.stringify(a[a.id]);oa(a.key,c)||(p("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}function Rb(a){var b=!0;try{a[a.id]=JSON.parse(a[a.id])}catch(c){p(c.message||c),b=!1}return b}function Sb(a,b){return b?(a[a.id]=b,a.a=!0):a.a?!0:ma()&&(b=na(a.key))?(a[a.id]=b,a.a=!0):!1}function Tb(a,b){return a[a.id][b]||null}function D(a,b,c){try{a[a.id][b]=c}catch(d){}}
function Ub(a,b,c){r.call(this,"Computer",a,Ub);this.g.H=!1;Vb(this,b);this.u=ib(this,"autoPower",a);this.f=0;this.F=a.busWidth||a.buswidth;this.b=Wb;this.o=null;this.j=this.D=!1;this.G=ib(this,"url")||"";(Math.random()+.1).toString(36);this.c=Xb(this);if(this.a=Fa("CPU",this.id)){this.J=Fa("Debugger",this.id);this.K=[];for(b=null;b=Ma(this,"Video",b);)this.K.push(b);this.C=new Oa({id:this.Na+".bus",buswidth:this.F},this.a,this.J);var d,e=v(this.id);if((this.h=Fa("Panel",this.id))&&this.h.Ea)for(b=
0;b<e.length;b++)d=e[b],d.I=this.h.I,d.L=this.h.L,d.Ea=this.h.Ea;for(b=0;b<e.length;b++)d=e[b],d.ma&&d.ma(this,this.C,this.a,this.J);b=null;d=a.resume;void 0!==d&&(1<d.length?b=this.m=d:this.b=parseInt(d,10));var f;if(a=ib(this,"state")||(f=!0,a.state))b=this.w=a,f||(this.j=!0,this.b=Wb),this.b&&(this.s=new C(this,Z),Sb(this.s)?b=null:delete this.s);!b&&this.b&&(b=Yb(this))&&(this.j=!0);if(b){var h=this;n(b,null,!0,function(a,b,c){c?(h.m=null,h.j=!1,h.I("Unable to load machine state from server (error "+
c+(b?": "+(String.prototype.trim?b.trim():b.replace(/^\s+|\s+$/g,"")):"")+")")):(h.o=b,h.D=!0);z(h)})}else z(this);this.v.power||(this.u=!0);!c&&this.u&&Zb(this,this.ta)}else p("Unable to find CPU component")}u(Ub);var Z="1.21.7",Wb=0;function Vb(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){p(d.message+" ("+c+")")}}a.l=b}
function ib(a,b,c){var d=b.toLowerCase(),d=ya[b]||ya[d];void 0===d&&a.l&&(d=a.l[b]);void 0===d&&c&&(d=c[b]);void 0===d&&"object"==typeof resources&&resources[b]&&(d=b);return d}function Zb(a,b,c){for(var d=v(a.id),e=0;e<=d.length;e++){var f=e<d.length?d[e]:a;if(!Ia(f)){Ia(f,function(){Zb(a,b,c)});return}}b.call(a,c)}
function $b(a,b){var c=new C(a,Z,"validate");if(Sb(c)&&Rb(c)){var d=Tb(c,"timestamp"),e=b?Tb(b,"timestamp"):"unknown";d!=e&&(a.I("Machine state may be out-of-date\n("+d+" vs. "+e+")\nCheck your browser's local storage limits"),b||c.clear())}}m=Ub.prototype;
m.ta=function(a){void 0===a&&(a=this.b||(this.o?1:Wb));if(!this.f){this.f++;var b=!1,c=!1;this.B=!1;var d=this.s||new C(this,Z);if(-1==a)b=!0;else if(a>Wb){if(Sb(d,this.o)){this.i=new C(this,Z,"failsafe");Sb(this.i)&&(ac(this,d),a=2,Pb(this.i));D(this.i,"timestamp",ia());Qb(this.i);var e=this.b&&!this.j;if(1==a||ka("Click OK to restore the previous PC8080 machine state, or CANCEL to reset the machine.")){if(c=Rb(d)){var f=Tb(d,"code"),h=Tb(d,"data");f&&("ok"==f?Sb(d,h):("error"==f&&"no machine state"!=
h?(this.I("Error: "+h),"unable to verify user"==h&&(oa("user",""),this.c=null)):this.L(f+": "+h),Pb(d),Sb(d)?(c=Rb(d),e=!0):c=!1))}e&&$b(this,c?d:null)}else 2==a&&d.clear()}else $b(this);delete this.o;delete this.s}e=v(this.id);for(f=0;f<e.length;f++)h=e[f],h!==this&&h!=this.a&&(c=bc(this,h,d,b,c));b=[d,a,c];-1!=a?Zb(this,this.Oa,b):this.Oa(b)}};
function bc(a,b,c,d,e){if(!b.g.H){b.g.H=!0;if(b.X){var f=null;e&&((f=Tb(c,b.id))||(f=Tb(c,b.id.replace(/[a-z0-9]\./i,"."))));"string"===typeof f&&(f=null);!b.X(f,d)&&f&&(p("Unable to restore state for "+b.type),a.w&&!a.D?(c.clear(),a.b=Wb,window&&window.location.reload()):a.B=!0,b.X(null),e=!1)}if(!d&&b.La)for(a=b.La.split("|"),c=0;c<a.length;c++)b.status(a[c])}return e}
m.Oa=function(a){var b=a[0],c=0>a[1];a=a[2];this.g.H=!0;var d=this.v.power;d&&(d.textContent="Shutdown");this.A||(this.L("PC8080 v"+Z+"\nCopyright \u00a9 2012-2016 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>"),this.A=!0);this.a&&(bc(this,this.a,b,c,a),mb(this.a));this.B&&(ac(this,b),b.clear());!c&&this.i&&(this.i.clear(),delete this.i);this.f=0};
function ac(a,b){if(ka("There may be a problem with your PC8080 machine.\n\nTo help us diagnose it, click OK to send this PC8080 machine state to http://www.pcjs.org.")){var c=a.G,d=a.c||"",e=b.toString(),f={app:"PC8080"};f.ver=Z;f.url=c;f.user=d;f.type="bug";f.data=e;n("http://www.pcjs.org/api/v1/report",f,!0)}}
function cc(a,b,c){var d,e="none";if(a.f)return null;a.f--;var f=new C(a,Z),h=new C(a,Z,"validate"),g=ia();D(h,"timestamp",g);D(f,"timestamp",g);D(f,"version","1.21.7");D(f,"url",window?window.location.href:null);D(f,"browser",window?window.navigator.userAgent:"");a.a&&a.a.W&&(c&&nb(a.a),d=a.a.W(b,c),"object"===typeof d&&D(f,a.a.id,d),c&&(a.a.g.H=!1,!1===d&&(e=null)));for(var g=v(a.id),k=0;k<g.length;k++){var l=g[k];l.g.H&&(l.W&&(d=l.W(b,c),"object"===typeof d&&D(f,l.id,d)),c&&(l.g.H=!1,!1===d&&(e=
null)))}e&&(c?(g=d=!1,b?(a.c&&dc(a,a.c,f.toString()),Qb(h)&&Qb(f)||(e=null,d=g=!0)):a.b&&(d=!0,g=3==a.b),d&&f.clear(g)):e=f.toString());c&&(a.g.H=!1,b=a.v.power)&&(b.textContent="Power");a.f=0;return e}m.reset=function(){this.C&&this.C.reset&&this.C.reset();for(var a=v(this.id),b=0;b<a.length;b++){var c=a[b];c!==this&&c!==this.C&&c.reset&&c.reset()}};m.start=function(a,b){for(var c=v(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.start&&e.start(a,b)}};
m.stop=function(a,b){for(var c=v(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.stop&&e.stop(a,b)}};
m.M=function(a,b,c){var d=this;switch(b){case "power":return this.v[b]=c,c.onclick=function(){d.f||(d.g.H?cc(d,!1,!0):Zb(d,d.ta))},!0;case "reset":return this.v[b]=c,c.onclick=function(){if(d.g.H&&!d.f)if(d.b&&!d.m){var a=ka("Click OK to save changes to this PC8080 machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");cc(d,a,!0);!a&&d.w?window&&window.location.reload():d.ta(Wb)}else d.reset(),d.a&&mb(d.a)},!0;case "save":if(ea(ja(),"pcjs.org")){c.parentNode.removeChild(c);break}this.v[b]=
c;c.onclick=function(){var a=Xb(d,!0);if(a){var b=!!(d.b&&!d.m||d.w),c=cc(d,b);b?dc(d,a,c):d.I("Resume disabled, machine state not saved")}};return!0}return!1};
function Xb(a,b){var c=a.c;c||(c=na("user"),void 0!==c?!c&&b&&(c=null,window&&(c=window.prompt("Saving machine states on the pcjs.org server is currently unsupported.\n\nIf you're running your own server, enter your user ID below.","")),c&&((c=ec(a,c))||a.I("The user ID is invalid."))):b&&a.I("Browser local storage is not available"));return c}
function ec(a,b){a.c=null;var c=n(ja()+"/api/v1/user?req=verify&user="+b),d=c[1];if(!c[0]&&d)try{c=eval("("+d+")"),c.code&&"ok"==c.code&&(oa("user",c.data),a.c=c.data)}catch(e){p(e.message+" ("+d+")")}return a.c}function Yb(a){var b=null;a.c&&(b=ja()+"/api/v1/user?req=load&user="+a.c+"&state="+Ob(a,Z));return b}
function dc(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=Ob(a,Z);d.data=c;b=n(ja()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var e=d.indexOf("\n");0<e&&(d=d.substr(0,e));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.I("Machine state saved to server"):c&&(c=b&&b.data||"unable to save machine state",c="error"==b.code?"Error: "+c:"Error "+b.code+": "+c,a.I(c),oa("user",""),a.c=null)}}
function Ma(a,b,c){a=v(a.id);for(var d=0;d<a.length;d++){var e=a[d];if(c)c==e&&(c=null);else if(e.type==b)return e}return null}m.ca=function(a){this.a&&this.a.ca(a);this.h&&this.h.ca(a)};ta(function(){for(var a=y(document,"pc8080-machine"),b=0;b<a.length;b++)for(var c=a[b],d=w(c),c=y(c,"pc8080","computer"),e=0;e<c.length;e++){var f=c[e],h=w(f),h=new Ub(h,d,!0);Ga(h,f);h.u&&Zb(h,h.ta)}});
q.show.push(function(){for(var a=y(document,"pc8080","computer"),b=0;b<a.length;b++){var c=w(a[b]);(c=Fa("Computer",c.id))&&c.A&&!c.g.H&&c.ta(-1)}});q.exit.push(function(){for(var a=y(document,"pc8080","computer"),b=0;b<a.length;b++){var c=w(a[b]);(c=Fa("Computer",c.id))&&c.g.H&&cc(c,!(!c.b||c.m),!0)}});var fc=0;function gc(a,b,c,d,e,f){e("Loading "+a+"...");n(a,null,!0,function(h,g,k){k?(g||(g="unable to load "+a+" ("+k+")"),f(g,null)):hc(g,a,b,c,d,e,f)})}
function hc(a,b,c,d,e,f,h){function g(a,f){if(f)h(f,null);else{if(c){Ea(c,b,a);var g=b;g&&0>g.indexOf("/")&&"/"==window.location.pathname.slice(-1)&&(g=window.location.pathname+g);d?"}"==d.slice(-1)?(d=d.slice(0,-1),1<d.length&&(d+=",")):d='{state:"'+d+'",':d="{";d+='url:"'+g+'"}';"object"==typeof resources&&(g=null);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" parms='"+d+"'":"")+(g?' url="'+g+'"':""))}e||(a=a.replace(/(<xsl:variable name="APPCLASS">).*?(<\/xsl:variable>)/,"$1pc8080$2"));
g=null;if("<"==a.charAt(0))try{e||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),window.ActiveXObject||"ActiveXObject"in window?(g=new window.ActiveXObject("Microsoft.XMLDOM"),g.async=!1,g.loadXML(a)):g=(new window.DOMParser).parseFromString(a,"text/xml")}catch(x){g=null,a=x.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);h(a,g)}}a?e?ic(a,f,g):g(a,null):h("no data"+(b?" for file: "+b:""),null)}
function ic(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var e=d[2];b("Loading "+e+"...");n(e,null,!0,function(f,h,g){if(g||!h)c(a,"unable to resolve XML reference: "+d[0]+" ("+g+")");else{if(f=d[3])if(g=h.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var k=g[0],l,H=/( [a-z]+=)(['"])(.*?)\2/g;l=H.exec(f);)k=0>k.indexOf(l[1])?k.replace(">",l[0]+">"):k.replace(new RegExp(l[1]+"(['\"])(.*?)\\1"),l[0]);g[0]!=k&&(h=h.replace(g[0],k))}else{c(a,"missing <"+d[1]+"> in "+e);return}h=h.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],h);ic(a,b,c)}})}else c(a,null)}
function jc(a,b,c,d){function e(a){if(void 0===g){var b=h&&y(h,"machine-warning");g=b&&b[0]||h}g&&(g.innerHTML=ga(a))}function f(a){e("Error: "+a);k&&(--fc||va(!0));k=!1}var h,g,k=!0;fc++;Da[a]={};try{if(h=document.getElementById(a)){var l;if("object"==typeof resources&&(l=resources.css)){var H=document.head||document.getElementsByTagName("head")[0],x=document.createElement("style");x.type="text/css";x.styleSheet?x.styleSheet.cssText=l:x.appendChild(document.createTextNode(l));H.appendChild(x)}c||
(c="/versions/pc8080/1.21.7/components.xsl");l=function(d,g){g?gc(c,null,null,!1,e,function(d,k){if(k)if(Ea(a,c,d),e("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var l=g.transformNode(k);l?(h.outerHTML=l,--fc||va(!0)):f("transformNodeToObject failed")}else document.implementation&&document.implementation.createDocument?(l=new XSLTProcessor,l.importStylesheet(k),(l=l.transformToFragment(g,document))?h.parentNode?(h.parentNode.replaceChild(l,h),--fc||va(!0)):f("invalid machine element: "+
a):f("transformToFragment failed")):f("unable to transform XML: unsupported browser");else f(d)}):f(d)};"<"!=b.charAt(0)?gc(b,a,d,!0,e,l):hc(b,null,a,d,!1,e,l)}else f("missing machine element: "+a)}catch(Qa){f(Qa.message)}return k}window.embedPC8080=function(a,b,c,d){va(!1);return jc(a,b,c,d)};window.enableEvents=va;window.sendEvent=wa;
function kc(a,b,c,d){if(!c&&b){d.push(b);a=Da[d[0]];b=null;for(var e in a)if(ea(e,"components.xsl")){b=e.replace(".xsl",".css");break}b?n(b,null,!0,function(a,b){lc(b,d)}):lc(null,d)}else p("Error ("+c+") requesting "+a)}
function lc(a,b){var c,d,e,f=b[0],h=b[1];c=b[4];c=c.match(/^(\s*\(function\(\)\{)([\s\S]*)(}\)\(\);\s*)$/);var g=Da[f],k={},l;for(l in g){var H=g[l],x=da(l);if("xml"==x){for(x=/[ \t]*<disk [^>]*path=(['"])(.*?)\1.*?<\/disk>\n?/g;d=x.exec(g[l]);){var Qa=d[2];Qa&&(g[Qa]||(H=H.replace(d[0],"")))}d=l=ca(l)}else"xsl"==x&&(e=l=ca(l));k[l]=H}a&&(k[l="css"]=a);b[2]&&(k[l="parms"]=b[2]);b[3]&&(k[l="state"]=b[3]);d&&e?(l=JSON.stringify(k),h+=".js",c=c[1]+"var resources="+l+";"+c[2]+c[3],c=c.replace(/\u00A9/g,
"&#xA9;"),l=h,g=null,k="data:application/javascript,",k=pa("Firefox")?k+encodeURIComponent(c):k+encodeURI(c),l&&(g=document.createElement("a"),"string"!=typeof g.download&&(g=null)),g?(g.href=k,g.download=l,document.body.appendChild(g),g.click(),document.body.removeChild(g),c="Check your Downloads folder for "+l+"."):(window.open(k),c="Check your browser for a new window/tab containing the requested data"+(l?" ("+l+")":"")+"."),c+=', copy it to your web server as "'+h+'", and then add the following to your web page:\n\n',
c+='<div id="'+f+'"></div>\n',c+="...\n",c+='<script type="text/javascript" src="'+h+'">\x3c/script>\n',c+='<script type="text/javascript">embedPC("'+f+'","'+d+'","'+e+'");\x3c/script>\n\n',c+="The machine should appear where the <div> is located.",p(c)):p("Missing XML/XSL resources")}
window.savePC=function(a,b,c){var d=Fa("Computer",a),e=Fa("Debugger",a);if(d){var f=cc(d,!0),h=d.l?JSON.stringify(d.l):null;b||(b="/versions/pcjs/1.21.7/pc"+(e?"-dbg":"")+".js");if(c&&c({state:f,Wa:h}))return!0;n(b,null,!0,function(c,d,e){kc(c,d,e,[a,ca(b,!0),h,f])});return!0}p("Unable to identify machine '"+a+"'");return!1};})();
function n(a,b){var c="";void 0===b?b=8:8<b&&(b=8);if(null==a||isNaN(a))for(;0<b--;)c="?"+c;else for(;0<b--;){var d=a&15,d=d+(0<=d&&9>=d?48:55),c=String.fromCharCode(d)+c;a>>=4}return c}function ba(a,b){var c=a,d=a.lastIndexOf("/");0<=d&&(c=a.substr(d+1));d=c.indexOf("&");0<d&&(c=c.substr(0,d));b&&(d=c.lastIndexOf("."),0<d&&(c=c.substring(0,d)));return c}function ca(a){var b="",c=a.lastIndexOf(".");0<=c&&(b=a.substr(c+1).toLowerCase());return b}
function da(a,b){return-1!==a.indexOf(b,a.length-b.length)}var ea={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};function fa(a){return a.replace(/[&<>"']/g,function(a){return ea[a]})}var ga=Date.now||function(){return+new Date};function ha(){function a(a){return(10>a?"0":"")+a}var b=new Date;return b.getFullYear()+"-"+a(b.getMonth()+1)+"-"+a(b.getDate())+" "+a(b.getHours())+":"+a(b.getMinutes())+":"+a(b.getSeconds())}
function p(a,b,c,d){var e=0,f=null,h=null;if("object"==typeof resources&&(f=resources[a]))return d&&d(a,f,e),[f,e];if(c&&"function"==typeof resources)return resources(a,function(b,c){d&&d(a,b,c)}),h;var g=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");c&&(g.onreadystatechange=function(){4===g.readyState&&(f=g.responseText,200==g.status||!g.status&&f.length&&"file:"==(window?window.location.protocol:"file:")||(e=g.status||-1),d&&d(a,f,e))});if(b&&"object"==
typeof b){var k="",l;for(l in b)b.hasOwnProperty(l)&&(k&&(k+="&"),k+=l+"="+encodeURIComponent(b[l]));k=k.replace(/%20/g,"+");g.open("POST",a,!!c);g.setRequestHeader("Content-type","application/x-www-form-urlencoded");g.send(k)}else g.open("GET",a,!!c),"bytes"==b&&g.overrideMimeType("text/plain; charset=x-user-defined"),g.send();c||(f=g.responseText,200!=g.status&&(e=g.status||-1),d&&d(a,f,e),h=[f,e]);return h}function ia(){return"http://"+(window?window.location.host:"www.pcjs.org")}
function q(a){window&&window.alert(a)}function ja(a){var b=!1;window&&(b=window.confirm(a));return b}var ka=null;function la(){if(null==ka){var a=!1;if(window)try{window.localStorage.setItem("PCjs.localStorage","PCjs.localStorage"),a="PCjs.localStorage"==window.localStorage.getItem("PCjs.localStorage"),window.localStorage.removeItem("PCjs.localStorage")}catch(b){a=!1}ka=a}return ka}function ma(a){var b;if(window)try{b=window.localStorage.getItem(a)}catch(c){}return b}
function na(a,b){try{return window.localStorage.setItem(a,b),!0}catch(c){}return!1}function oa(a){if(window){var b=window?window.navigator.userAgent:"";return"iOS"==a&&b.match(/(iPod|iPhone|iPad)/)&&b.match(/AppleWebKit/)||"MSIE"==a&&b.match(/(MSIE|Trident)/)||0<=b.indexOf(a)?!0:!1}return!1}var r={init:[],show:[],exit:[]},pa=!1,qa=!0;function ra(a,b){if(window){var c=window[a];window[a]="function"!==typeof c?b:function(){c&&c();b()}}}function t(a){r.init.push(a)}
function sa(a){if(qa)try{for(var b=0;b<a.length;b++)a[b]()}catch(c){q("An unexpected exception occurred:\n\n"+c.message+"\n\nPlease send this information to support@pcjs.org. Thanks.")}}function ta(a){!qa&&a?(qa=!0,pa&&ua("init")):qa=a}function ua(a){r[a]&&sa(r[a])}ra("onload",function(){pa=!0;sa(r.init)});ra("onpageshow",function(){sa(r.show)});ra(oa("Opera")||oa("iOS")?"onunload":"onbeforeunload",function(){sa(r.exit)});
function u(a,b,c){this.type=a;b||(b={id:"",name:""});this.id=b.id;this.name=b.name;this.Pa=b.comment;this.$a=b;void 0===this.id&&(this.id="");b=this.id.indexOf(".");0<b?(this.Ra=this.id.substr(0,b),this.Qa=this.id.substr(b+1)):this.Qa=this.id;this[a]=c;this.g={ga:!1,pa:!1,Ha:!1,J:!1,aa:!1};this.Aa=null;this.g.aa=!1;this.v={};this.I=null;v.push(this)}var va=void 0,wa={};
if(window){va||(va=window.location.search.substr(1));for(var xa,ya=/\+/g,za=/([^&=]+)=?([^&]*)/g;xa=za.exec(va);)wa[decodeURIComponent(xa[1].replace(ya," "))]=decodeURIComponent(xa[2].replace(ya," "))}function Aa(a){function b(){}if(window){if(!a)throw new TypeError;if(Object.create)return Object.create(a);var c=typeof a;if("object"!==c&&"function"!==c)throw new TypeError;}b.prototype=a;return new b}
function x(a,b){b||(b=u);a.prototype=Aa(b.prototype);a.prototype.constructor=a;a.prototype.parent=b.prototype}var v=[],Ba={};function Ca(a,b,c){Ba[a]&&b&&(Ba[a][b]=c)}function y(a){var b,c=[];a&&(a=0<(b=a.indexOf("."))?a.substr(0,b+1):"");for(b=0;b<v.length;b++){var d=v[b];a&&d.id.indexOf(a)||c.push(d)}return c}
function Da(a,b){var c;if(void 0!==a){var d;b&&(b=0<(d=b.indexOf("."))?b.substr(0,d+1):"");for(d=0;d<v.length;d++)if(c)c==v[d]&&(c=null);else if(!(a!=v[d].type||b&&v[d].id.indexOf(b)))return v[d]}return null}function z(a){var b=null;if(a=a.getAttribute("data-value"))try{b=eval("("+a+")")}catch(c){q(c.message+" ("+a+")")}return b}
function Ea(a,b){for(var c=A(b.parentNode,"pc8080-control"),d=0;d<c.length;d++)for(var e=c[d].childNodes,f=0;f<e.length;f++){var h=e[f];if(1===h.nodeType){var g=h.getAttribute("class");if(g)for(var k=g.split(" "),l=0;l<k.length;l++)switch(g=k[l],g){case "pc8080-binding":(g=z(h))&&g.binding&&a.M(g.type,g.binding,h,g.value),l=k.length}}}}
function A(a,b,c){c&&(b+="-"+c+"-object");if(a.getElementsByClassName)return a.getElementsByClassName(b);var d;c=[];a=a.getElementsByTagName("*");var e=new RegExp("(^| )"+b+"( |$)");b=0;for(d=a.length;b<d;b++)e.test(a[b].className)&&c.push(a[b]);return c}
u.prototype={constructor:u,parent:null,toString:function(){return this.name?this.name:this.id||this.type},M:function(a,b,c){switch(b){case "clear":return this.v[b]||(this.v[b]=c,c.onclick=function(a){return function(){a.v.print&&(a.v.print.value="")}}(this)),!0;case "print":return this.v[b]||(this.Ga=this.v[b]=c,c.value="",this.O=function(a){return function(b,c){8192<a.value.length&&(a.value=a.value.substr(a.value.length-4096));a.value+=(void 0!==c?c+": ":"")+(b||"")+"\n";a.scrollTop=a.scrollHeight}}(c),
this.K=function(a,b,c){this.O(a,"notice",c)}),!0;default:return!1}},log:function(){},O:function(){},status:function(a){this.O(this.Qa+": "+a)},K:function(a,b){b||q(a)},W:function(){return this.g.J=!0},V:function(a,b){b&&(this.g.J=!1);return!0}};function Fa(a,b){if(a.g.Ha)return a.g.pa&&(a.g.pa=!1),a.g.Ha=!1;if(a.g.aa)return a.O(a.toString()+" error"),!1;a.g.pa=b;return a.g.pa}function B(a){if(!a.g.aa&&(a.g.ga=!0,a.g.ga)){var b=a.Aa;a.Aa=null;b&&b()}}
function Ga(a,b){b&&(a.g.ga?b():a.Aa=b);return a.g.ga}
var Ha="undefined"!==typeof ArrayBuffer,Ia=[1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,
0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1];function Ja(a){u.call(this,"Panel",a,Ja)}x(Ja);m=Ja.prototype;m.M=function(a,b,c,d){return this.w&&this.w.M(a,b,c,d)||this.a&&this.a.M(a,b,c,d)||this.b&&this.b.M(a,b,c,d)?!0:this.parent.M.call(this,a,b,c,d)};m.ba=function(a,b,c,d){this.w=a;this.B=b;this.a=c;this.I=d;this.b=Ka(a,"Keyboard")};m.W=function(a,b){b||La();return!0};m.V=function(){return!0};m.ea=function(){};
function La(){for(var a=!1,b=A(document,"pc8080","panel"),c=0;c<b.length;c++){var d=b[c],e=z(d),f;a:{f=e.id;if(void 0!==f)for(var h=void 0,h=0;h<v.length;h++)if(v[h].id===f){f=v[h];break a}f=null}f||(a=!0,f=new Ja(e));Ea(f,d);a&&B(f)}}t(La);
function Ma(a,b,c){u.call(this,"Bus",a,Ma);this.a=b;this.I=c;this.h=a.buswidth||16;this.m=Math.pow(2,this.h);this.f=this.m-1|0;this.G=20>=this.h?12:24>=this.h?14:15;this.H=1<<this.G;this.o=this.H>>2;this.l=this.H-1;this.c=this.m/this.H|0;this.i=[];this.j=[];this.s=[];this.u=[];a=new C;Na(a,this.I);this.b=Array(this.c);for(b=0;b<this.c;b++)this.b[b]=a;a=this.a;b=this.b;c=this.G;var d=this.f;a.N=b;a.G=c;a.H=1<<a.G;a.S=a.H-1;a.Ma=b.length;a.na=a.Ma-1;a.Z=d;B(this)}x(Ma);Ma.prototype.reset=function(){};
Ma.prototype.W=function(a,b){b||this.reset();return!0};function Oa(a,b,c,d){for(var e=b>>>a.G;0<c&&e<a.b.length;){var f=a.b[e],h=e*a.H,g=c>a.H?a.H:c;if(f&&f.size){if(f.type==d){if(b+c<=f.oa)return f.Fa+=f.oa-b,f.oa=b,!0;if(b>=f.oa+f.Fa){g=f.size-(b-h);g>c&&(g=c);f.Fa=b-f.oa+g;c-=g;b=h+a.H;continue}}return Pa(1,b,c)}f=a.b[e];b=new C(b,g,a.H,d);Na(b,a.I,f);a.b[e++]=b;b=h+a.H;c-=g}return 0>=c?!0:Pa(2,b,c)}Ma.prototype.D=function(a){return this.b[(a&this.f)>>>this.G].ma(a&this.l,a)};
function Pa(a,b,c){q("Memory block error ("+a+": "+n(b)+","+n(c)+")");return!1}var Qa;if(Ha){var Sa=new ArrayBuffer(2);(new DataView(Sa)).setUint16(0,256,!0);Qa=256===(new Uint16Array(Sa))[0]}else Qa=!1;var Ta=Qa;
function C(a,b,c,d){this.id=Ua+=2;this.a=null;this.oa=a;this.Fa=b;this.size=c||0;this.type=d||Va;this.h=d==Wa;Na(this);this.Y=this.gb=!1;if(c)if(Ha)this.c=new ArrayBuffer(c),this.f=new DataView(this.c,0,c),this.b=new Uint8Array(this.c,0,c),this.l=new Uint16Array(this.c,0,c>>1),this.a=new Int32Array(this.c,0,c>>2),Xa(this,Ta?Ya:Za);else{this.a=Array(c>>2);for(a=0;a<this.a.length;a++)this.a[a]=0;Xa(this,$a)}else Xa(this)}var Va=0,Wa=2,Ua=0;
C.prototype={constructor:C,parent:null,save:function(){var a,b;if(Ha)for(a=Array(this.size>>2),b=0;b<a.length;b++)a[b]=this.f.getInt32(b<<2,!0);else a=this.a;return a},restore:function(a){if(a&&this.size==a.length<<2){var b;if(Ha)for(b=0;b<a.length;b++)this.f.setInt32(b<<2,a[b],!0);else this.a=a;return this.Y=!0}return!1},m:function(){return 255},s:function(){},o:function(a,b){return this.ma(a++,b++)|this.ma(a,b)<<8},v:function(a,b,c){this.xa(a++,b&255,c++);this.xa(a,b>>8,c)},C:function(a){return this.a[a>>
2]>>>((a&3)<<3)&255},N:function(a){var b=a>>2;a=(a&3)<<3;var c=this.a[b]>>a;return 24>a?c&65535:c&255|(this.a[b+1]&255)<<8},U:function(a,b){var c=a>>2,d=(a&3)<<3;this.a[c]=this.a[c]&~(255<<d)|b<<d;this.Y=!0},na:function(a,b){var c=a>>2,d=(a&3)<<3;24>d?this.a[c]=this.a[c]&~(65535<<d)|b<<d:(this.a[c]=this.a[c]&16777215|b<<24,c++,this.a[c]=this.a[c]&-256|b>>8);this.Y=!0},w:function(a,b){return this.B(a,b)},G:function(a,b){return this.H(a,b)},S:function(a,b,c){this.h||this.bb(a,b,c)},Z:function(a,b,c){this.h||
this.$(a,b,c)},u:function(a){return this.b[a]},A:function(a){return this.b[a]},F:function(a){return this.f.getUint16(a,!0)},L:function(a){return a&1?this.b[a]|this.b[a+1]<<8:this.l[a>>1]},P:function(a,b){this.b[a]=b;this.Y=!0},T:function(a,b){this.b[a]=b;this.Y=!0},X:function(a,b){this.f.setUint16(a,b,!0);this.Y=!0},fa:function(a,b){a&1?(this.b[a]=b,this.b[a+1]=b>>8):this.l[a>>1]=b;this.Y=!0}};function Na(a,b,c){a.I=b;a.i=a.j=0;c&&((a.i=c.i)&&ab(a,bb,!1),(a.j=c.j)&&cb(a,bb,!1))}
function cb(a,b,c){c&&a.j||(a.xa=!a.h&&b[2]||a.s,a.sb=!a.h&&b[3]||a.v);if(c||void 0===c)a.bb=b[2]||a.s,a.$=b[3]||a.v}function ab(a,b,c){c&&a.i||(a.ma=b[0]||a.m,a.qb=b[1]||a.o);if(c||void 0===c)a.B=b[0]||a.m,a.H=b[1]||a.o}function Xa(a,b){b||(b=db);ab(a,b,void 0);cb(a,b,void 0)}var db=[],$a=[C.prototype.C,C.prototype.N,C.prototype.U,C.prototype.na],bb=[C.prototype.w,C.prototype.G,C.prototype.S,C.prototype.Z];
if(Ha)var Za=[C.prototype.u,C.prototype.F,C.prototype.P,C.prototype.X],Ya=[C.prototype.A,C.prototype.L,C.prototype.T,C.prototype.fa];
function eb(a,b){u.call(this,"CPU",a,eb);var c=a.cycles||b,d=a.multiplier||1;this.c={};this.c.la=c;this.c.Ea=0;this.c.ka=d;this.c.Ia=Math.round(this.c.la/1E4)/100;this.c.ha=this.c.Ia*this.c.ka;this.g.R=!1;this.g.Va=!1;this.g.Ta=a.autoStart;this.g.Ua=!1;this.g.ya=!1;this.c.Ca=this.c.ja=0;this.c.Da=a.csStart;this.c.qa=a.csInterval;this.c.ra=a.csStop;this.cb=this.La.bind(this);B(this)}x(eb);var fb=["power","reset"];m=eb.prototype;
m.ba=function(a,b,c,d){this.w=a;this.B=b;this.I=d;for(b=0;b<fb.length;b++)(c=this.v[fb[b]])&&this.w.M(null,fb[b],c);this.X=(b=Ka(a,"Video"))&&Math.max(b.X,b.eb)||60;this.fa=Ka(a,"ChipSet");a=gb(a,"autoStart");null!=a&&(this.g.Ta="true"==a?!0:"false"==a?!1:!!a);B(this)};m.reset=function(){this.c.Ea=0};m.save=function(){return null};m.restore=function(){return!1};
m.W=function(a,b){if(!b){if(a&&this.restore){hb(this);if(!this.restore(a))return!1;ib(this)}else this.reset();this.O("No debugger detected")}jb(this);return!0};m.V=function(a){return a?this.save():!0};function kb(a){(a.g.Ta||void 0===a.v.run)&&a.La()}m.Wa=function(){return 0};function ib(a){void 0===a.c.Da&&(a.c.Da=0);void 0===a.c.qa&&(a.c.qa=-1);void 0===a.c.ra&&(a.c.ra=-1);a.g.ya=0<=a.c.Da&&0<a.c.qa;a.g.ya&&(a.c.Ca=0,a.c.ja=a.c.Da-a.U)}
m.M=function(a,b,c){var d=this;a=!1;switch(b){case "power":case "reset":this.v[b]=c;a=!0;break;case "run":this.v[b]=c;c.onclick=function(){var a;if(a=d.w)if(a=d.w,a.g.J)a=!0;else{var b=null,c,g=y(a.id);for(c=0;c<g.length&&(b=g[c],b===a||b.g.ga);c++);if(c==g.length)for(c=0;c<g.length&&(b=g[c],b===a||b.g.J);c++);c==g.length&&(b=a);q("The "+b.type+" component ("+b.id+") is not "+(b.g.ga?"powered yet":"ready yet"+(b.Aa?" (waiting for notification)":""))+".");a=!1}a&&(d.g.R?lb(d,!0):d.La())};a=!0;break;
case "speed":this.v[b]=c;a=!0;break;case "setSpeed":this.v[b]=c,c.onclick=function(){mb(d,d.c.ka<<1)},c.textContent=this.c.ha.toFixed(2)+"Mhz",a=!0}return a};function nb(a,b,c){a.U+=b;c&&(a.T=a.a=0)}
function ob(a,b){var c=30;c<a.X&&(c=a.X);2>c&&(c=2);var d=1;b&&1<a.c.ka&&a.c.ca&&(d=a.c.ca/a.c.Ia);a.c.Xa=Math.round(1E3/30);a.c.lb=Math.floor(a.c.la/c*d);a.c.Ja=Math.floor(a.c.la/30*d);a.c.Za=Math.floor(a.c.la/a.X*d);a.c.Ya=Math.floor(a.c.la/2*d);b||(a.c.ua=a.c.Ja,a.c.ta=a.c.Za,a.c.sa=a.c.Ya);a.c.Ka=0}function pb(a){return a.U+a.P+a.T-a.a}function hb(a){a.c.ca=0;a.U=a.P=a.T=a.a=0;ib(a);mb(a,1)}
function mb(a,b){if(void 0!==b){.8>a.c.ca/a.c.ha&&(b=1);a.c.ka=b;var c=a.c.Ia*a.c.ka;if(a.c.ha!=c){a.c.ha=c;var c=a.c.ha.toFixed(2)+"Mhz",d=a.v.setSpeed;d&&(d.textContent=c);a.O("target speed: "+c)}}nb(a,a.P);a.P=0;a.c.ia=ga();a.c.da=0;ob(a)}
m.La=function(){if(Fa(this,!0)){if(!this.g.R){mb(this);this.w&&this.w.start(this.c.ia,pb(this));this.g.R=!0;this.g.Va=!0;this.fa&&this.fa.rb();var a=this.v.run;a&&(a.textContent="Halt");this.w&&this.w.ea(!0)}this.c.Ka>=this.c.la&&ob(this,!0);this.c.va=0;this.c.Ba=ga();this.c.da&&(a=this.c.Ba-this.c.da,a>this.c.Xa&&(this.c.ia+=a,this.c.ia>this.c.Ba&&(this.c.ia=this.c.Ba)));try{do{var b=this.g.ya?1:this.c.lb;try{this.ab(b)}catch(e){if("number"!=typeof e)throw e;}var c=this.T-this.a;this.P+=c;this.c.va+=
c;nb(this,0,!0);a=c;if(this.g.ya){var d=!1;this.c.Ca=this.c.Ca+this.Wa()|0;this.c.ja-=a;0>=this.c.ja&&(this.c.ja+=this.c.qa,d=!0);0<=this.c.ra&&this.c.ra<=pb(this)&&(this.c.qa=this.c.ra=-1,ib(this),lb(this),d=!0);d&&this.O(pb(this)+" cycles: checksum="+n(this.c.Ca))}this.c.ta-=c;0>=this.c.ta&&(this.c.ta+=this.c.Za,this.w&&qb(this.w,this.c.Ea++),this.c.Ea>this.X&&(this.c.Ea=0));this.c.sa-=c;0>=this.c.sa&&(this.c.sa+=this.c.Ya,this.w&&this.w.ea());this.c.ua-=c;if(0>=this.c.ua){this.c.ua+=this.c.Ja;
break}}while(this.g.R)}catch(e){lb(this);jb(this);this.w&&this.w.stop(ga(),pb(this));Fa(this,!1);b=e.stack||e.message;this.g.aa=!0;this.K(b);return}b=setTimeout;c=this.cb;this.c.da=ga();a=this.c.Xa;this.c.va&&(a=Math.round(a*this.c.va/this.c.Ja));a-=this.c.da-this.c.Ba;if(d=this.c.da-this.c.ia)this.c.ca=Math.round(this.P/(10*d))/100,864E5<=d&&(this.U=0,mb(this));if(0>a||this.c.ca<this.c.ha)a=0;this.c.Ka+=this.c.va;this.c.da+=a;b(c,a)}else jb(this),this.w&&this.w.stop(ga(),pb(this))};m.ab=function(){return 0};
function lb(a,b){a.g.pa&&(a.g.Ha=!0);a.T-=a.a;a.a=0;nb(a,a.P);a.P=0;if(a.g.R){a.g.R=!1;a.fa&&a.fa.rb();var c=a.v.run;c&&(c.textContent="Run")}a.g.za=b}function jb(a){a.w&&(qb(a.w,-1),a.w.ea(void 0))}function rb(a){this.$=a.model||8080;eb.call(this,a,1E6);this.Na=sb;hb(this);this.g.za=this.g.fb=!1;this.Oa=0;this.N=[];this.G=this.H=this.S=this.Ma=this.na=this.Z=0;tb(this)}x(rb,eb);m=rb.prototype;m.reset=function(){this.g.R&&lb(this);tb(this);hb(this);this.g.aa=!1;this.parent.reset.call(this)};
function tb(a){a.b=0;a.h=0;a.i=0;a.j=0;a.l=0;a.m=0;a.o=0;a.A=0;D(a,0);ub(a,0);a.F=0}m.Wa=function(){var a=this.b+this.h+this.i+this.j+this.l+this.m+this.o|0;return a=a+this.A+this.u+vb(this)|0};
m.save=function(){var a=new E(this);F(a,0,[this.b,this.h,this.i,this.j,this.l,this.m,this.o,this.A,this.u,vb(this)]);F(a,1,[this.F,this.U,this.c.ka]);for(var b=this.B,c=0,d=[],e=0;e<b.c;e++){var f=b.b[e];if(f.Y||f.gb){d[c++]=e;var h=c++;a:if(f=f.save()){for(var g=0,k=0,l=[];g<f.length;){for(var H=f[g],w=g+1;w<f.length&&f[w]===H;)w++;l[k++]=w-g;l[k++]=H;g=w}if(l.length<f.length){f=l;break a}}d[h]=f}}F(a,2,d);return a.data()};
m.restore=function(a){var b=a[0];this.b=b[0];this.h=b[1];this.i=b[2];this.j=b[3];this.l=b[4];this.m=b[5];this.o=b[6];this.A=b[7]&65535;D(this,b[8]);ub(this,b[9]);b=a[1];this.F=b[0];this.U=b[1];mb(this,b[3]);a:{b=this.B;a=a[2];var c;for(c=0;c<a.length-1;c+=2){var d=a[c],e=a[c+1];if(e&&e.length<b.o){for(var f=0,h=Array(b.o),g=0;g<e.length-1;)for(var k=e[g++],l=e[g++];k--;)h[f++]=l;e=h}f=b.b[d];if(!f||!f.restore(e)){q("Unable to restore memory block "+d);b=!1;break a}}b=!0}return b};
m.M=function(a,b,c){var d=!1;switch(b){case "A":case "B":case "C":case "D":case "E":case "H":case "L":case "SP":case "PC":case "F":case "SF":case "ZF":case "AF":case "PF":case "CF":this.v[b]=c;this.Oa++;d=!0;break;default:d=this.parent.M.call(this,a,b,c)}return d};function wb(a){return a.h<<8|a.i}function xb(a,b){a.h=b>>8&255;a.i=b&255}function yb(a){return a.j<<8|a.l}function zb(a,b){a.j=b>>8&255;a.l=b&255}function G(a){return a.m<<8|a.o}function I(a,b){a.m=b>>8&255;a.o=b&255}
function D(a,b){a.u=b&65535}function J(a){return a.f&256?1:0}function Ab(a){return Ia[a.s&255]?4:0}function vb(a){return a.L&-214|(a.s&128?128:0)|(a.f&255?0:64)|((a.s^a.C)&16?16:0)|Ab(a)|J(a)}function ub(a,b){a.f=a.s=a.C=0;b&1&&(a.f|=256);b&4||(a.s|=1);b&16&&(a.C|=16);b&64||(a.f|=255);b&128&&(a.s^=192);a.L=a.L&-513|b&512|2}function K(a,b){a.C=a.b^b;return(a.f=a.s=a.b+b)&255}function L(a,b){a.C=a.b^b;return(a.f=a.s=a.b+b+(a.f&256?1:0))&255}function M(a,b){return a.f=a.s=a.C=a.b&b}
function N(a,b){a.C=a.b^b;a.f=a.s=a.b-b}function Bb(a,b){a.C=b;b=(a.s=b-1)&255;a.f=a.f&-256|b;return b}function Cb(a,b){a.C=b;b=(a.s=b+1)&255;a.f=a.f&-256|b;return b}function O(a,b){return a.f=a.s=a.C=a.b|b}function P(a,b){a.C=a.b^b;return(a.f=a.s=a.b-b)&255}function Q(a,b){a.C=a.b^b;return(a.f=a.s=a.b-b-(a.f&256?1:0))&255}function R(a,b){return a.f=a.s=a.C=a.b^b}m.D=function(a){return this.N[(a&this.Z)>>>this.G].ma(a&this.S,a)};
function Db(a,b){var c=b&a.S,d=(b&a.Z)>>>a.G;if(c<a.S)return a.N[d].qb(c,b);c=a.N[d].ma(c,b);return c|=a.N[d+1&a.na].ma(0,b+1)<<8}function S(a,b,c){a.N[(b&a.Z)>>>a.G].xa(b&a.S,c&255,b)}function Eb(a,b,c){var d=b&a.S,e=(b&a.Z)>>>a.G;d<a.S?a.N[e].sb(d,c&65535,b):(a.N[e++].xa(d,c&255,b),a.N[e&a.na].xa(0,c>>8&255,b+1))}function T(a){var b=a.D(a.u);D(a,a.u+1);return b}function U(a){var b=Db(a,a.u);D(a,a.u+2);return b}function V(a){var b=Db(a,a.A);a.A=a.A+2&65535;return b}
function W(a,b){a.A=a.A-2&65535;Eb(a,a.A,b)}function X(a,b,c,d){d=d||2;a.v[b]&&(void 0===c&&(a.g.aa=!0,a.K("Value for "+b+" is invalid"),lb(a)),c=!a.g.R||a.g.Ua?n(c,d):"--------".substr(0,d),a.v[b].textContent!=c&&(a.v[b].textContent=c))}
m.ea=function(a){this.Oa&&(a||!this.g.R||this.g.Ua)&&(X(this,"A",this.b),X(this,"B",this.h),X(this,"C",this.i),X(this,"D",this.j),X(this,"E",this.l),X(this,"H",this.m),X(this,"L",this.o),X(this,"SP",this.A,4),X(this,"PC",this.u,4),a=vb(this),X(this,"F",a,2),X(this,"SF",a&128,1),X(this,"ZF",a&64,1),X(this,"AF",a&16,1),X(this,"PF",a&4,1),X(this,"CF",a&1,1));if(a=this.v.speed)a.textContent=this.g.R&&this.c.ca?this.c.ca.toFixed(2)+"Mhz":"Stopped"};
m.ab=function(a){this.g.za=!0;this.g.fb=!1;this.g.Va=!1;this.T=this.a=a;do{if(a=this.F)this.F&8&&this.L&512?(a=199|(this.F&7)<<3,this.F&=-16,this.L&=-513,this.Na[a].call(this),a=!0):a=!1,a=!a;if(a&&this.F&16){this.a=0;break}this.Na[T(this)].call(this)}while(0<this.a);return this.g.za?this.T-this.a:void 0===this.g.za?0:-1};t(function(){for(var a=A(document,"pc8080","cpu"),b=0;b<a.length;b++){var c=a[b],d=z(c),d=new rb(d);Ea(d,c)}});function Fb(){this.a-=4}function Gb(){D(this,U(this));this.a-=10}
function Hb(){D(this,V(this));this.a-=10}function Ib(){var a=U(this);W(this,this.u);D(this,a);this.a-=17}
var sb=[Fb,function(){xb(this,U(this));this.a-=10},function(){S(this,wb(this),this.b);this.a-=7},function(){xb(this,wb(this)+1);this.a-=5},function(){this.h=Cb(this,this.h);this.a-=5},function(){this.h=Bb(this,this.h);this.a-=5},function(){this.h=T(this);this.a-=7},function(){var a=this.b<<1;this.b=a&255|a>>8;this.f=this.f&255|a&256;this.a-=4},Fb,function(){var a;I(this,a=G(this)+wb(this));this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=this.D(wb(this));this.a-=7},function(){xb(this,wb(this)-
1);this.a-=5},function(){this.i=Cb(this,this.i);this.a-=5},function(){this.i=Bb(this,this.i);this.a-=5},function(){this.i=T(this);this.a-=7},function(){var a=this.b<<8&256;this.b=(a|this.b)>>1;this.f=this.f&255|a;this.a-=4},Fb,function(){zb(this,U(this));this.a-=10},function(){S(this,yb(this),this.b);this.a-=7},function(){zb(this,yb(this)+1);this.a-=5},function(){this.j=Cb(this,this.j);this.a-=5},function(){this.j=Bb(this,this.j);this.a-=5},function(){this.j=T(this);this.a-=7},function(){var a=this.b<<
1;this.b=a&255|this.f>>8;this.f=this.f&255|a&256;this.a-=4},Fb,function(){var a;I(this,a=G(this)+yb(this));this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=this.D(yb(this));this.a-=7},function(){zb(this,yb(this)-1);this.a-=5},function(){this.l=Cb(this,this.l);this.a-=5},function(){this.l=Bb(this,this.l);this.a-=5},function(){this.l=T(this);this.a-=7},function(){var a=this.b<<8&256;this.b=(this.f&256|this.b)>>1;this.f=this.f&255|a;this.a-=4},Fb,function(){I(this,U(this));this.a-=10},function(){Eb(this,
U(this),G(this));this.a-=16},function(){I(this,G(this)+1);this.a-=5},function(){this.m=Cb(this,this.m);this.a-=5},function(){this.m=Bb(this,this.m);this.a-=5},function(){this.m=T(this);this.a-=7},function(){var a=this.b,b=!!J(this),c=!!((this.s^this.C)&16);9<(a&15)||c?(a+=6,c=!0):c=!1;160<=a||b?(a+=96,b=!0):b=!1;this.f=this.s=this.b=a&255;this.f=b?this.f|256:this.f&-257;this.C=c?~this.s&16|this.C&-17:this.s&16|this.C&-17;this.a-=4},Fb,function(){var a;I(this,a=G(this)+G(this));this.f=this.f&255|a>>
8&256;this.a-=10},function(){I(this,Db(this,U(this)));this.a-=16},function(){I(this,G(this)-1);this.a-=5},function(){this.o=Cb(this,this.o);this.a-=5},function(){this.o=Bb(this,this.o);this.a-=5},function(){this.o=T(this);this.a-=7},function(){this.b=~this.b&255;this.a-=4},Fb,function(){this.A=U(this)&65535;this.a-=10},function(){S(this,U(this),this.b);this.a-=13},function(){this.A=this.A+1&65535;this.a-=5},function(){var a=G(this);S(this,a,Cb(this,this.D(a)));this.a-=10},function(){var a=G(this);
S(this,a,Bb(this,this.D(a)));this.a-=10},function(){S(this,G(this),T(this));this.a-=10},function(){this.f|=256;this.a-=4},Fb,function(){var a;this.A=(a=G(this)+this.A)&65535;this.f=this.f&255|a>>8&256;this.a-=10},function(){this.b=this.D(U(this));this.a-=13},function(){this.A=this.A-1&65535;this.a-=5},function(){this.b=Cb(this,this.b);this.a-=5},function(){this.b=Bb(this,this.b);this.a-=5},function(){this.b=T(this);this.a-=7},function(){this.f=J(this)?this.f&-257:this.f|256;this.a-=4},function(){this.a-=
5},function(){this.h=this.i;this.a-=5},function(){this.h=this.j;this.a-=5},function(){this.h=this.l;this.a-=5},function(){this.h=this.m;this.a-=5},function(){this.h=this.o;this.a-=5},function(){this.h=this.D(G(this));this.a-=7},function(){this.h=this.b;this.a-=5},function(){this.i=this.h;this.a-=5},function(){this.a-=5},function(){this.i=this.j;this.a-=5},function(){this.i=this.l;this.a-=5},function(){this.i=this.m;this.a-=5},function(){this.i=this.o;this.a-=5},function(){this.i=this.D(G(this));this.a-=
7},function(){this.i=this.b;this.a-=5},function(){this.j=this.h;this.a-=5},function(){this.j=this.i;this.a-=5},function(){this.a-=5},function(){this.j=this.l;this.a-=5},function(){this.j=this.m;this.a-=5},function(){this.j=this.o;this.a-=5},function(){this.j=this.D(G(this));this.a-=7},function(){this.j=this.b;this.a-=5},function(){this.l=this.h;this.a-=5},function(){this.l=this.i;this.a-=5},function(){this.l=this.j;this.a-=5},function(){this.a-=5},function(){this.l=this.m;this.a-=5},function(){this.l=
this.o;this.a-=5},function(){this.l=this.D(G(this));this.a-=7},function(){this.l=this.b;this.a-=5},function(){this.m=this.h;this.a-=5},function(){this.m=this.i;this.a-=5},function(){this.m=this.j;this.a-=5},function(){this.m=this.l;this.a-=5},function(){this.a-=5},function(){this.m=this.o;this.a-=5},function(){this.m=this.D(G(this));this.a-=7},function(){this.m=this.b;this.a-=5},function(){this.o=this.h;this.a-=5},function(){this.o=this.i;this.a-=5},function(){this.o=this.j;this.a-=5},function(){this.o=
this.l;this.a-=5},function(){this.o=this.m;this.a-=5},function(){this.a-=5},function(){this.o=this.D(G(this));this.a-=7},function(){this.o=this.b;this.a-=5},function(){S(this,G(this),this.h);this.a-=7},function(){S(this,G(this),this.i);this.a-=7},function(){S(this,G(this),this.j);this.a-=7},function(){S(this,G(this),this.l);this.a-=7},function(){S(this,G(this),this.m);this.a-=7},function(){S(this,G(this),this.o);this.a-=7},function(){this.F|=16;this.a-=7;this.L&512||lb(this)},function(){S(this,G(this),
this.b);this.a-=7},function(){this.b=this.h;this.a-=5},function(){this.b=this.i;this.a-=5},function(){this.b=this.j;this.a-=5},function(){this.b=this.l;this.a-=5},function(){this.b=this.m;this.a-=5},function(){this.b=this.o;this.a-=5},function(){this.b=this.D(G(this));this.a-=7},function(){this.a-=5},function(){this.b=K(this,this.h);this.a-=4},function(){this.b=K(this,this.i);this.a-=4},function(){this.b=K(this,this.j);this.a-=4},function(){this.b=K(this,this.l);this.a-=4},function(){this.b=K(this,
this.m);this.a-=4},function(){this.b=K(this,this.o);this.a-=4},function(){this.b=K(this,this.D(G(this)));this.a-=7},function(){this.b=K(this,this.b);this.a-=4},function(){this.b=L(this,this.h);this.a-=4},function(){this.b=L(this,this.i);this.a-=4},function(){this.b=L(this,this.j);this.a-=4},function(){this.b=L(this,this.l);this.a-=4},function(){this.b=L(this,this.m);this.a-=4},function(){this.b=L(this,this.o);this.a-=4},function(){this.b=L(this,this.D(G(this)));this.a-=7},function(){this.b=L(this,
this.b);this.a-=4},function(){this.b=P(this,this.h);this.a-=4},function(){this.b=P(this,this.i);this.a-=4},function(){this.b=P(this,this.j);this.a-=4},function(){this.b=P(this,this.l);this.a-=4},function(){this.b=P(this,this.m);this.a-=4},function(){this.b=P(this,this.o);this.a-=4},function(){this.b=P(this,this.D(G(this)));this.a-=7},function(){this.b=P(this,this.b);this.a-=4},function(){this.b=Q(this,this.h);this.a-=4},function(){this.b=Q(this,this.i);this.a-=4},function(){this.b=Q(this,this.j);
this.a-=4},function(){this.b=Q(this,this.l);this.a-=4},function(){this.b=Q(this,this.m);this.a-=4},function(){this.b=Q(this,this.o);this.a-=4},function(){this.b=Q(this,this.D(G(this)));this.a-=7},function(){this.b=Q(this,this.b);this.a-=4},function(){this.b=M(this,this.h);this.a-=4},function(){this.b=M(this,this.i);this.a-=4},function(){this.b=M(this,this.j);this.a-=4},function(){this.b=M(this,this.l);this.a-=4},function(){this.b=M(this,this.m);this.a-=4},function(){this.b=M(this,this.o);this.a-=
4},function(){this.b=M(this,this.D(G(this)));this.a-=7},function(){this.b=M(this,this.b);this.a-=4},function(){this.b=R(this,this.h);this.a-=4},function(){this.b=R(this,this.i);this.a-=4},function(){this.b=R(this,this.j);this.a-=4},function(){this.b=R(this,this.l);this.a-=4},function(){this.b=R(this,this.m);this.a-=4},function(){this.b=R(this,this.o);this.a-=4},function(){this.b=R(this,this.D(G(this)));this.a-=7},function(){this.b=R(this,this.b);this.a-=4},function(){this.b=O(this,this.h);this.a-=
4},function(){this.b=O(this,this.i);this.a-=4},function(){this.b=O(this,this.j);this.a-=4},function(){this.b=O(this,this.l);this.a-=4},function(){this.b=O(this,this.m);this.a-=4},function(){this.b=O(this,this.o);this.a-=4},function(){this.b=O(this,this.D(G(this)));this.a-=7},function(){this.b=O(this,this.b);this.a-=4},function(){N(this,this.h);this.a-=4},function(){N(this,this.i);this.a-=4},function(){N(this,this.j);this.a-=4},function(){N(this,this.l);this.a-=4},function(){N(this,this.m);this.a-=
4},function(){N(this,this.o);this.a-=4},function(){N(this,this.D(G(this)));this.a-=7},function(){N(this,this.b);this.a-=4},function(){this.f&255&&(D(this,V(this)),this.a-=6);this.a-=5},function(){xb(this,V(this));this.a-=10},function(){var a=U(this);this.f&255&&D(this,a);this.a-=10},Gb,function(){var a=U(this);this.f&255&&(W(this,this.u),D(this,a),this.a-=6);this.a-=11},function(){W(this,wb(this));this.a-=11},function(){this.b=K(this,T(this));this.a-=7},function(){W(this,this.u);D(this,0);this.a-=
11},function(){this.f&255||(D(this,V(this)),this.a-=6);this.a-=5},Hb,function(){var a=U(this);this.f&255||D(this,a);this.a-=10},Gb,function(){var a=U(this);this.f&255||(W(this,this.u),D(this,a),this.a-=6);this.a-=11},Ib,function(){this.b=L(this,T(this));this.a-=7},function(){W(this,this.u);D(this,8);this.a-=11},function(){J(this)||(D(this,V(this)),this.a-=6);this.a-=5},function(){zb(this,V(this));this.a-=10},function(){var a=U(this);J(this)||D(this,a);this.a-=10},function(){for(var a=T(this),b=this.B,
c=this.b,d=1,e=0;0<d;){var f=b.j[a],h=b.u[a]||1,g=1==h?255:2==h?65535:-1,g=(c>>>=e)&g;if(void 0!==f&&f[0])f[0](a,g,void 0);e+=h<<3;a+=h;d-=h}this.a-=10},function(){var a=U(this);J(this)||(W(this,this.u),D(this,a),this.a-=6);this.a-=11},function(){W(this,yb(this));this.a-=11},function(){this.b=P(this,T(this));this.a-=7},function(){W(this,this.u);D(this,16);this.a-=11},function(){J(this)&&(D(this,V(this)),this.a-=6);this.a-=5},Hb,function(){var a=U(this);J(this)&&D(this,a);this.a-=10},function(){for(var a=
T(this),b=this.B,c=1,d=0,e=0;0<c;){var f=b.i[a],h=b.s[a]||1,g=1==h?255:2==h?65535:-1,k=g;void 0!==f&&f[0]&&(k=f[0](a,void 0),void 0===k?k=g:k&=g);d|=k<<e;e+=h<<3;a+=h;c-=h}this.b=d&255;this.a-=10},function(){var a=U(this);J(this)&&(W(this,this.u),D(this,a),this.a-=6);this.a-=11},Ib,function(){this.b=Q(this,T(this));this.a-=7},function(){W(this,this.u);D(this,24);this.a-=11},function(){Ab(this)||(D(this,V(this)),this.a-=6);this.a-=5},function(){I(this,V(this));this.a-=10},function(){var a=U(this);
Ab(this)||D(this,a);this.a-=10},function(){var a=V(this);W(this,G(this));I(this,a);this.a-=18},function(){var a=U(this);Ab(this)||(W(this,this.u),D(this,a),this.a-=6);this.a-=11},function(){W(this,G(this));this.a-=11},function(){this.b=M(this,T(this));this.a-=7},function(){W(this,this.u);D(this,32);this.a-=11},function(){Ab(this)&&(D(this,V(this)),this.a-=6);this.a-=5},function(){D(this,G(this));this.a-=5},function(){var a=U(this);Ab(this)&&D(this,a);this.a-=10},function(){var a=G(this);I(this,yb(this));
zb(this,a);this.a-=5},function(){var a=U(this);Ab(this)&&(W(this,this.u),D(this,a),this.a-=6);this.a-=11},Ib,function(){this.b=R(this,T(this));this.a-=7},function(){W(this,this.u);D(this,40);this.a-=11},function(){this.s&128||(D(this,V(this)),this.a-=6);this.a-=5},function(){var a=V(this);ub(this,a);this.b=a>>8;this.a-=10},function(){var a=U(this);this.s&128||D(this,a);this.a-=10},function(){this.L&=-513;this.a-=4},function(){var a=U(this);this.s&128||(W(this,this.u),D(this,a),this.a-=6);this.a-=
11},function(){W(this,vb(this)&255|this.b<<8);this.a-=11},function(){this.b=O(this,T(this));this.a-=7},function(){W(this,this.u);D(this,48);this.a-=11},function(){this.s&128&&(D(this,V(this)),this.a-=6);this.a-=5},function(){this.A=G(this)&65535;this.a-=5},function(){var a=U(this);this.s&128&&D(this,a);this.a-=10},function(){this.L|=512;this.a-=4},function(){var a=U(this);this.s&128&&(W(this,this.u),D(this,a),this.a-=6);this.a-=11},Ib,function(){N(this,T(this));this.a-=7},function(){W(this,this.u);
D(this,56);this.a-=11}];function Y(a){u.call(this,"ChipSet",a,Y);var b=a.model;b&&!Jb[b]&&q("Unrecognized ChipSet model: "+b);this.$=Jb[b];a.sound&&(this.m=null,window&&(this.m=window.AudioContext||window.webkitAudioContext),this.m&&new this.m);B(this)}x(Y);var Jb={SI1978:1978.1};m=Y.prototype;m.M=function(){return!1};
m.ba=function(a,b,c,d){this.B=b;this.a=c;this.I=d;this.w=a;if(1978.1==this.$){var e;a=Kb;void 0===e&&(e=0);for(var f in a){c=b;d=+f+e;var h=a[f].bind(this);if(void 0!==h)for(var g=+f+e;g<=d;g++)void 0!==c.i[g]?q("Input port 0x"+n(g,4)+" already registered"):c.i[g]=[h,!1]}var k;e=Lb;void 0===k&&(k=0);for(var l in e)if(f=b,a=+l+k,c=e[l].bind(this),void 0!==c)for(d=+l+k;d<=a;d++)void 0!==f.j[d]?q("Output port 0x"+n(d,4)+" already registered"):f.j[d]=[c,!1]}};
m.W=function(a,b){if(!b)if(!a)this.reset();else if(!this.restore(a))return!1;return!0};m.V=function(a){return a?this.save():!0};m.reset=function(){this.f=this.h=this.b=this.c=this.l=this.j=this.i=0};m.save=function(){var a=new E(this);1978.1==this.$&&F(a,0,[this.i,this.j,this.l,this.c,this.b,this.f,this.h]);return a.data()};m.restore=function(a){a=a[0];1978.1==this.$&&(this.i=a[0],this.j=a[1],this.l=a[2],this.c=a[3],this.b=a[4],this.f=a[5],this.h=a[6]);return!0};m.ib=function(){return this.i};
m.jb=function(){return this.j};m.kb=function(){return this.l};m.hb=function(){return this.c<<this.b>>8&255};m.mb=function(a,b){this.b=b};m.ob=function(a,b){this.f=b};m.nb=function(a,b){this.c=b};m.pb=function(a,b){this.h=b};var Kb={0:Y.prototype.ib,1:Y.prototype.jb,2:Y.prototype.kb,3:Y.prototype.hb},Lb={2:Y.prototype.mb,3:Y.prototype.ob,4:Y.prototype.nb,5:Y.prototype.pb};t(function(){for(var a=A(document,"pc8080","chipset"),b=0;b<a.length;b++){var c=a[b],d=z(c),d=new Y(d);Ea(d,c)}});
function Mb(a){u.call(this,"ROM",a,Mb);this.b=null;this.j=a.addr;this.c=a.size;this.f=a.alias;this.h=a.file;this.l=ba(this.h);if(this.h){a=this.h;var b=ca(this.l);"json"!=b&&"hex"!=b&&(a=ia()+"/api/v1/dump?file="+this.h+"&format=bytes&decimal=true");var c=this;p(a,null,!0,function(a,b,f){Nb(c,a,b,f)})}}x(Mb);Mb.prototype.ba=function(a,b,c,d){this.B=b;this.a=c;this.I=d;Ob(this)};Mb.prototype.W=function(){this.i&&(this.I&&this.I.a(this.id,this.j,this.c,this.i),delete this.i);return!0};
Mb.prototype.V=function(){return!0};
function Nb(a,b,c,d){if(d)a.K("Unable to load system ROM (error "+d+": "+b+")");else{Ca(a.Ra,b,c);if("["==c.charAt(0)||"{"==c.charAt(0))try{var e=eval("("+c+")"),f=e.bytes,h=e.data;if(f)a.b=f;else if(h)for(a.b=Array(4*h.length),d=c=0;c<h.length;c++)a.b[d++]=h[c]&255,a.b[d++]=h[c]>>8&255,a.b[d++]=h[c]>>16&255,a.b[d++]=h[c]>>24&255;else a.b=e;a.i=e.symbols;if(!a.b.length){q("Empty ROM: "+b);return}if(1==a.b.length){q(a.b[0]);return}}catch(g){a.K("ROM data error: "+g.message);return}else for(b=c.replace(/\n/gm,
" ").replace(/ +$/,"").split(" "),a.b=Array(b.length),e=0;e<b.length;e++)a.b[e]=aa(b[e]);Ob(a)}}
function Ob(a){if(!Ga(a))if(!a.h)B(a);else if(a.b&&a.B){if(a.b.length!=a.c){var b="ROM size (0x"+n(a.b.length)+") does not match specified size ("+("0x"+n(a.c))+")";a.g.aa=!0;a.K(b)}else{b=a.j;if(Oa(a.B,b,a.c,Wa)){for(var c=0;c<a.b.length;c++){var d=a.B,e=b+c;d.b[(e&d.f)>>>d.G].bb(e&d.l,a.b[c]&255,e)}b=!0}else b=!1;if(b){b=[];"number"==typeof a.f?b.push(a.f):null!=a.f&&a.f.length&&(b=a.f);for(c=0;c<b.length;c++){for(var f=a,d=b[c],e=f.B,h=f.c,g=[],k=f.j>>>e.G;0<h&&k<e.b.length;)g.push(e.b[k++]),h-=
e.H;e=f.B;f=f.c;h=0;for(d>>>=e.G;0<f&&d<e.b.length;){k=g[h++];if(!k)break;e.b[d++]=k;f-=e.H}}delete a.b}}B(a)}}t(function(){for(var a=A(document,"pc8080","rom"),b=0;b<a.length;b++){var c=a[b],d=z(c),d=new Mb(d);Ea(d,c)}});function Pb(a){u.call(this,"RAM",a,Pb);this.f=a.addr;this.c=a.size;this.b=!1}x(Pb);m=Pb.prototype;m.ba=function(a,b,c,d){this.B=b;this.a=c;this.I=d;B(this)};m.W=function(a,b){b||this.reset();return!0};m.V=function(a){return a?this.save():!0};
m.reset=function(){!this.b&&this.c&&Oa(this.B,this.f,this.c,1)&&(this.b=!0,this.status(Math.floor(this.c/1024)+"Kb allocated"));this.b||q("No RAM allocated")};m.save=function(){return null};m.restore=function(){return!0};t(function(){for(var a=A(document,"pc8080","ram"),b=0;b<a.length;b++){var c=a[b],d=z(c),d=new Pb(d);Ea(d,c)}});function Qb(a){u.call(this,"Keyboard",a,Qb);B(this)}x(Qb);t(function(){for(var a=A(document,"pc8080","keyboard"),b=0;b<a.length;b++){var c=a[b],d=z(c),d=new Qb(d);Ea(d,c)}});
function Rb(a){u.call(this,"Video",a,Rb);this.eb=a.interruptRate;this.X=a.refreshRate||60;B(this)}x(Rb);Rb.prototype.ba=function(a,b,c,d){this.w=a;this.B=b;this.a=c;this.I=d};
t(function(){for(var a=A(document,"pc8080","video"),b=0;b<a.length;b++){var c=a[b],d=z(c),e=document.createElement("canvas");if(void 0===e||!e.getContext){c.innerHTML="<br/>Missing &lt;canvas&gt; support. Please try a newer web browser.";break}e.setAttribute("class","pcjs-canvas");e.setAttribute("width",d.screenWidth);e.setAttribute("height",d.screenHeight);e.style.backgroundColor=d.screenColor;e.style.height="auto";0<=(window?window.navigator.userAgent:"").indexOf("MSIE")&&(c.onresize=function(a,
b,c,d){return function(){b.style.height=(a.clientWidth*d/c|0)+"px"}}(c,e,d.screenWidth,d.screenHeight),c.onresize());var f=+(d.aspect||wa.aspect);f&&.3<=f&&3.33>=f&&(ra("onresize",function(a,b,c){return function(){b.style.height=(a.clientWidth/c|0)+"px"}}(c,e,f)),window.onresize());c.appendChild(e);f=document.createElement("textarea");oa("iOS")&&(f.setAttribute("autocapitalize","off"),f.setAttribute("autocorrect","off"));c.appendChild(f);e.getContext("2d");d=new Rb(d);Ea(d,c)}});
function E(a,b,c){this.id=a.id;this.key=Sb(a,b,c);this.I=a.I;Tb(this,a.$a)}function Sb(a,b,c){a=a.id;if(b){var d=b.indexOf(".");0<d&&(a+=".v"+b.substr(0,d))}c&&(a+="."+c);return a}
E.prototype={constructor:E,value:function(){return this[this.id]},data:function(){return this[this.id]},toString:function(){var a=this[this.id];return"string"==typeof a?a:JSON.stringify(a)},clear:function(a){Tb(this);var b=[];try{for(var c=0,d=window.localStorage.length;c<d;c++)b.push(window.localStorage.key(c))}catch(e){}for(c=0;c<b.length;c++)if((d=b[c])&&(a||d.substr(0,this.key.length)==this.key)){try{window.localStorage.removeItem(d)}catch(e){}b.splice(c,1);c=0}}};
function Tb(a,b){a[a.id]={};b&&F(a,"parms",b);a.a=!1}function Ub(a){var b=!0;if(la()){var c=JSON.stringify(a[a.id]);na(a.key,c)||(q("Unable to store "+c.length+" bytes in browser local storage"),b=!1)}return b}function Vb(a){var b=!0;try{a[a.id]=JSON.parse(a[a.id])}catch(c){q(c.message||c),b=!1}return b}function Wb(a,b){return b?(a[a.id]=b,a.a=!0):a.a?!0:la()&&(b=ma(a.key))?(a[a.id]=b,a.a=!0):!1}function Xb(a,b){return a[a.id][b]||null}function F(a,b,c){try{a[a.id][b]=c}catch(d){}}
function Yb(a,b,c){u.call(this,"Computer",a,Yb);this.g.J=!1;Zb(this,b);this.w=gb(this,"autoPower",a);this.f=0;this.H=a.busWidth||a.buswidth;this.b=$b;this.o=null;this.j=this.G=!1;this.L=gb(this,"url")||"";(Math.random()+.1).toString(36);this.c=ac(this);if(this.a=Da("CPU",this.id)){this.I=Da("Debugger",this.id);this.u=[];for(b=null;b=Ka(this,"Video",b);)this.u.push(b);this.B=new Ma({id:this.Ra+".bus",buswidth:this.H},this.a,this.I);var d,e=y(this.id);if((this.h=Da("Panel",this.id))&&this.h.Ga)for(b=
0;b<e.length;b++)d=e[b],d.K=this.h.K,d.O=this.h.O,d.Ga=this.h.Ga;for(b=0;b<e.length;b++)d=e[b],d.ba&&d.ba(this,this.B,this.a,this.I);b=null;d=a.resume;void 0!==d&&(1<d.length?b=this.m=d:this.b=parseInt(d,10));var f;if(a=gb(this,"state")||(f=!0,a.state))b=this.A=a,f||(this.j=!0,this.b=$b),this.b&&(this.s=new E(this,Z),Wb(this.s)?b=null:delete this.s);!b&&this.b&&(b=bc(this))&&(this.j=!0);if(b){var h=this;p(b,null,!0,function(a,b,c){c?(h.m=null,h.j=!1,h.K("Unable to load machine state from server (error "+
c+(b?": "+(String.prototype.trim?b.trim():b.replace(/^\s+|\s+$/g,"")):"")+")")):(h.o=b,h.G=!0);B(h)})}else B(this);this.v.power||(this.w=!0);!c&&this.w&&cc(this,this.wa)}else q("Unable to find CPU component")}x(Yb);var Z="1.21.7",$b=0;function Zb(a,b){if(!b){var c;if("object"==typeof resources&&(c=resources.parms))try{b=eval("("+c+")")}catch(d){q(d.message+" ("+c+")")}}a.l=b}
function gb(a,b,c){var d=b.toLowerCase(),d=wa[b]||wa[d];void 0===d&&a.l&&(d=a.l[b]);void 0===d&&c&&(d=c[b]);void 0===d&&"object"==typeof resources&&resources[b]&&(d=b);return d}function cc(a,b,c){for(var d=y(a.id),e=0;e<=d.length;e++){var f=e<d.length?d[e]:a;if(!Ga(f)){Ga(f,function(){cc(a,b,c)});return}}b.call(a,c)}
function dc(a,b){var c=new E(a,Z,"validate");if(Wb(c)&&Vb(c)){var d=Xb(c,"timestamp"),e=b?Xb(b,"timestamp"):"unknown";d!=e&&(a.K("Machine state may be out-of-date\n("+d+" vs. "+e+")\nCheck your browser's local storage limits"),b||c.clear())}}m=Yb.prototype;
m.wa=function(a){void 0===a&&(a=this.b||(this.o?1:$b));if(!this.f){this.f++;var b=!1,c=!1;this.F=!1;var d=this.s||new E(this,Z);if(-1==a)b=!0;else if(a>$b){if(Wb(d,this.o)){this.i=new E(this,Z,"failsafe");Wb(this.i)&&(ec(this,d),a=2,Tb(this.i));F(this.i,"timestamp",ha());Ub(this.i);var e=this.b&&!this.j;if(1==a||ja("Click OK to restore the previous PC8080 machine state, or CANCEL to reset the machine.")){if(c=Vb(d)){var f=Xb(d,"code"),h=Xb(d,"data");f&&("ok"==f?Wb(d,h):("error"==f&&"no machine state"!=
h?(this.K("Error: "+h),"unable to verify user"==h&&(na("user",""),this.c=null)):this.O(f+": "+h),Tb(d),Wb(d)?(c=Vb(d),e=!0):c=!1))}e&&dc(this,c?d:null)}else 2==a&&d.clear()}else dc(this);delete this.o;delete this.s}e=y(this.id);for(f=0;f<e.length;f++)h=e[f],h!==this&&h!=this.a&&(c=fc(this,h,d,b,c));b=[d,a,c];-1!=a?cc(this,this.Sa,b):this.Sa(b)}};
function fc(a,b,c,d,e){if(!b.g.J){b.g.J=!0;if(b.W){var f=null;e&&((f=Xb(c,b.id))||(f=Xb(c,b.id.replace(/[a-z0-9]\./i,"."))));"string"===typeof f&&(f=null);!b.W(f,d)&&f&&(q("Unable to restore state for "+b.type),a.A&&!a.G?(c.clear(),a.b=$b,window&&window.location.reload()):a.F=!0,b.W(null),e=!1)}if(!d&&b.Pa)for(a=b.Pa.split("|"),c=0;c<a.length;c++)b.status(a[c])}return e}
m.Sa=function(a){var b=a[0],c=0>a[1];a=a[2];this.g.J=!0;var d=this.v.power;d&&(d.textContent="Shutdown");this.C||(this.O("PC8080 v"+Z+"\nCopyright \u00a9 2012-2016 Jeff Parsons <Jeff@pcjs.org>\nLicense: GPL version 3 or later <http://gnu.org/licenses/gpl.html>"),this.C=!0);this.a&&(fc(this,this.a,b,c,a),kb(this.a));this.F&&(ec(this,b),b.clear());!c&&this.i&&(this.i.clear(),delete this.i);this.f=0};
function ec(a,b){if(ja("There may be a problem with your PC8080 machine.\n\nTo help us diagnose it, click OK to send this PC8080 machine state to http://www.pcjs.org.")){var c=a.L,d=a.c||"",e=b.toString(),f={app:"PC8080"};f.ver=Z;f.url=c;f.user=d;f.type="bug";f.data=e;p("http://www.pcjs.org/api/v1/report",f,!0)}}
function gc(a,b,c){var d,e="none";if(a.f)return null;a.f--;var f=new E(a,Z),h=new E(a,Z,"validate"),g=ha();F(h,"timestamp",g);F(f,"timestamp",g);F(f,"version","1.21.7");F(f,"url",window?window.location.href:null);F(f,"browser",window?window.navigator.userAgent:"");a.a&&a.a.V&&(c&&lb(a.a),d=a.a.V(b,c),"object"===typeof d&&F(f,a.a.id,d),c&&(a.a.g.J=!1,!1===d&&(e=null)));for(var g=y(a.id),k=0;k<g.length;k++){var l=g[k];l.g.J&&(l.V&&(d=l.V(b,c),"object"===typeof d&&F(f,l.id,d)),c&&(l.g.J=!1,!1===d&&(e=
null)))}e&&(c?(g=d=!1,b?(a.c&&hc(a,a.c,f.toString()),Ub(h)&&Ub(f)||(e=null,d=g=!0)):a.b&&(d=!0,g=3==a.b),d&&f.clear(g)):e=f.toString());c&&(a.g.J=!1,b=a.v.power)&&(b.textContent="Power");a.f=0;return e}m.reset=function(){this.B&&this.B.reset&&this.B.reset();for(var a=y(this.id),b=0;b<a.length;b++){var c=a[b];c!==this&&c!==this.B&&c.reset&&c.reset()}};m.start=function(a,b){for(var c=y(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.start&&e.start(a,b)}};
m.stop=function(a,b){for(var c=y(this.id),d=0;d<c.length;d++){var e=c[d];"CPU"!=e.type&&e!==this&&e.stop&&e.stop(a,b)}};
m.M=function(a,b,c){var d=this;switch(b){case "power":return this.v[b]=c,c.onclick=function(){d.f||(d.g.J?gc(d,!1,!0):cc(d,d.wa))},!0;case "reset":return this.v[b]=c,c.onclick=function(){if(d.g.J&&!d.f)if(d.b&&!d.m){var a=ja("Click OK to save changes to this PC8080 machine.\n\nWARNING: If you CANCEL, all disk changes will be discarded.");gc(d,a,!0);!a&&d.A?window&&window.location.reload():d.wa($b)}else d.reset(),d.a&&kb(d.a)},!0;case "save":if(da(ia(),"pcjs.org")){c.parentNode.removeChild(c);break}this.v[b]=
c;c.onclick=function(){var a=ac(d,!0);if(a){var b=!!(d.b&&!d.m||d.A),c=gc(d,b);b?hc(d,a,c):d.K("Resume disabled, machine state not saved")}};return!0}return!1};
function ac(a,b){var c=a.c;c||(c=ma("user"),void 0!==c?!c&&b&&(c=null,window&&(c=window.prompt("Saving machine states on the pcjs.org server is currently unsupported.\n\nIf you're running your own server, enter your user ID below.","")),c&&((c=ic(a,c))||a.K("The user ID is invalid."))):b&&a.K("Browser local storage is not available"));return c}
function ic(a,b){a.c=null;var c=p(ia()+"/api/v1/user?req=verify&user="+b),d=c[1];if(!c[0]&&d)try{c=eval("("+d+")"),c.code&&"ok"==c.code&&(na("user",c.data),a.c=c.data)}catch(e){q(e.message+" ("+d+")")}return a.c}function bc(a){var b=null;a.c&&(b=ia()+"/api/v1/user?req=load&user="+a.c+"&state="+Sb(a,Z));return b}
function hc(a,b,c){if(c){var d={req:"store"};d.user=b;d.state=Sb(a,Z);d.data=c;b=p(ia()+"/api/v1/user",d);d=b[0];if(b[1]){if(d){var e=d.indexOf("\n");0<e&&(d=d.substr(0,e));d.indexOf("Error: ")||(d=d.substr(7))}d='{"code":'+b[1]+',"data":"'+d+'"}'}b=JSON.parse(d);b&&"ok"==b.code?a.K("Machine state saved to server"):c&&(c=b&&b.data||"unable to save machine state",c="error"==b.code?"Error: "+c:"Error "+b.code+": "+c,a.K(c),na("user",""),a.c=null)}}
function Ka(a,b,c){a=y(a.id);for(var d=0;d<a.length;d++){var e=a[d];if(c)c==e&&(c=null);else if(e.type==b)return e}return null}m.ea=function(a){this.a&&this.a.ea(a);this.h&&this.h.ea(a)};function qb(a,b){for(var c=0;c<a.u.length;c++){var d=a.u[c];b&1?(d=d.a,d.F=d.F&-8|10):(d=d.a,d.F=d.F&-8|9)}}t(function(){for(var a=A(document,"pc8080-machine"),b=0;b<a.length;b++)for(var c=a[b],d=z(c),c=A(c,"pc8080","computer"),e=0;e<c.length;e++){var f=c[e],h=z(f),h=new Yb(h,d,!0);Ea(h,f);h.w&&cc(h,h.wa)}});
r.show.push(function(){for(var a=A(document,"pc8080","computer"),b=0;b<a.length;b++){var c=z(a[b]);(c=Da("Computer",c.id))&&c.C&&!c.g.J&&c.wa(-1)}});r.exit.push(function(){for(var a=A(document,"pc8080","computer"),b=0;b<a.length;b++){var c=z(a[b]);(c=Da("Computer",c.id))&&c.g.J&&gc(c,!(!c.b||c.m),!0)}});var jc=0;function kc(a,b,c,d,e,f){e("Loading "+a+"...");p(a,null,!0,function(h,g,k){k?(g||(g="unable to load "+a+" ("+k+")"),f(g,null)):lc(g,a,b,c,d,e,f)})}
function lc(a,b,c,d,e,f,h){function g(a,f){if(f)h(f,null);else{if(c){Ca(c,b,a);var g=b;g&&0>g.indexOf("/")&&"/"==window.location.pathname.slice(-1)&&(g=window.location.pathname+g);d?"}"==d.slice(-1)?(d=d.slice(0,-1),1<d.length&&(d+=",")):d='{state:"'+d+'",':d="{";d+='url:"'+g+'"}';"object"==typeof resources&&(g=null);a=a.replace(/(<machine[^>]*\sid=)(['"]).*?\2/,"$1$2"+c+"$2"+(d?" parms='"+d+"'":"")+(g?' url="'+g+'"':""))}e||(a=a.replace(/(<xsl:variable name="APPCLASS">).*?(<\/xsl:variable>)/,"$1pc8080$2"));
g=null;if("<"==a.charAt(0))try{e||(a=a.replace(/<!DOCTYPE(.|[\r\n])*]>\s*/g,"")),window.ActiveXObject||"ActiveXObject"in window?(g=new window.ActiveXObject("Microsoft.XMLDOM"),g.async=!1,g.loadXML(a)):g=(new window.DOMParser).parseFromString(a,"text/xml")}catch(w){g=null,a=w.message}else a="unrecognized XML: "+(255<a.length?a.substr(0,255)+"...":a);h(a,g)}}a?e?mc(a,f,g):g(a,null):h("no data"+(b?" for file: "+b:""),null)}
function mc(a,b,c){var d;if(d=/<([a-z]+)\s+ref="(.*?)"(.*?)\/>/g.exec(a)){var e=d[2];b("Loading "+e+"...");p(e,null,!0,function(f,h,g){if(g||!h)c(a,"unable to resolve XML reference: "+d[0]+" ("+g+")");else{if(f=d[3])if(g=h.match(new RegExp("<"+d[1]+"[^>]*>"))){for(var k=g[0],l,H=/( [a-z]+=)(['"])(.*?)\2/g;l=H.exec(f);)k=0>k.indexOf(l[1])?k.replace(">",l[0]+">"):k.replace(new RegExp(l[1]+"(['\"])(.*?)\\1"),l[0]);g[0]!=k&&(h=h.replace(g[0],k))}else{c(a,"missing <"+d[1]+"> in "+e);return}h=h.replace(/<\?xml[^>]*>[\r\n]*/,
"");a=a.replace(d[0],h);mc(a,b,c)}})}else c(a,null)}
function nc(a,b,c,d){function e(a){if(void 0===g){var b=h&&A(h,"machine-warning");g=b&&b[0]||h}g&&(g.innerHTML=fa(a))}function f(a){e("Error: "+a);k&&(--jc||ta(!0));k=!1}var h,g,k=!0;jc++;Ba[a]={};try{if(h=document.getElementById(a)){var l;if("object"==typeof resources&&(l=resources.css)){var H=document.head||document.getElementsByTagName("head")[0],w=document.createElement("style");w.type="text/css";w.styleSheet?w.styleSheet.cssText=l:w.appendChild(document.createTextNode(l));H.appendChild(w)}c||
(c="/versions/pc8080/1.21.7/components.xsl");l=function(d,g){g?kc(c,null,null,!1,e,function(d,k){if(k)if(Ca(a,c,d),e("Processing "+b+"..."),window.ActiveXObject||"ActiveXObject"in window){var l=g.transformNode(k);l?(h.outerHTML=l,--jc||ta(!0)):f("transformNodeToObject failed")}else document.implementation&&document.implementation.createDocument?(l=new XSLTProcessor,l.importStylesheet(k),(l=l.transformToFragment(g,document))?h.parentNode?(h.parentNode.replaceChild(l,h),--jc||ta(!0)):f("invalid machine element: "+
a):f("transformToFragment failed")):f("unable to transform XML: unsupported browser");else f(d)}):f(d)};"<"!=b.charAt(0)?kc(b,a,d,!0,e,l):lc(b,null,a,d,!1,e,l)}else f("missing machine element: "+a)}catch(Ra){f(Ra.message)}return k}window.embedPC8080=function(a,b,c,d){ta(!1);return nc(a,b,c,d)};window.enableEvents=ta;window.sendEvent=ua;
function oc(a,b,c,d){if(!c&&b){d.push(b);a=Ba[d[0]];b=null;for(var e in a)if(da(e,"components.xsl")){b=e.replace(".xsl",".css");break}b?p(b,null,!0,function(a,b){pc(b,d)}):pc(null,d)}else q("Error ("+c+") requesting "+a)}
function pc(a,b){var c,d,e,f=b[0],h=b[1];c=b[4];c=c.match(/^(\s*\(function\(\)\{)([\s\S]*)(}\)\(\);\s*)$/);var g=Ba[f],k={},l;for(l in g){var H=g[l],w=ca(l);if("xml"==w){for(w=/[ \t]*<disk [^>]*path=(['"])(.*?)\1.*?<\/disk>\n?/g;d=w.exec(g[l]);){var Ra=d[2];Ra&&(g[Ra]||(H=H.replace(d[0],"")))}d=l=ba(l)}else"xsl"==w&&(e=l=ba(l));k[l]=H}a&&(k[l="css"]=a);b[2]&&(k[l="parms"]=b[2]);b[3]&&(k[l="state"]=b[3]);d&&e?(l=JSON.stringify(k),h+=".js",c=c[1]+"var resources="+l+";"+c[2]+c[3],c=c.replace(/\u00A9/g,
"&#xA9;"),l=h,g=null,k="data:application/javascript,",k=oa("Firefox")?k+encodeURIComponent(c):k+encodeURI(c),l&&(g=document.createElement("a"),"string"!=typeof g.download&&(g=null)),g?(g.href=k,g.download=l,document.body.appendChild(g),g.click(),document.body.removeChild(g),c="Check your Downloads folder for "+l+"."):(window.open(k),c="Check your browser for a new window/tab containing the requested data"+(l?" ("+l+")":"")+"."),c+=', copy it to your web server as "'+h+'", and then add the following to your web page:\n\n',
c+='<div id="'+f+'"></div>\n',c+="...\n",c+='<script type="text/javascript" src="'+h+'">\x3c/script>\n',c+='<script type="text/javascript">embedPC("'+f+'","'+d+'","'+e+'");\x3c/script>\n\n',c+="The machine should appear where the <div> is located.",q(c)):q("Missing XML/XSL resources")}
window.savePC=function(a,b,c){var d=Da("Computer",a),e=Da("Debugger",a);if(d){var f=gc(d,!0),h=d.l?JSON.stringify(d.l):null;b||(b="/versions/pcjs/1.21.7/pc"+(e?"-dbg":"")+".js");if(c&&c({state:f,$a:h}))return!0;p(b,null,!0,function(c,d,e){oc(c,d,e,[a,ba(b,!0),h,f])});return!0}q("Unable to identify machine '"+a+"'");return!1};})();