Limit CPU display updates to a reasonable number (ie, twice per second)

This commit is contained in:
Jeff 2016-11-14 20:10:18 -08:00 committed by Jeff Parsons
commit 77897275eb
5 changed files with 247 additions and 238 deletions

View file

@ -1067,8 +1067,8 @@ ComputerPDP11.prototype.updateDisplays = function(nUpdate)
* nUpdate will also be -1 whenever the Debugger has modified the state of the machine, implying that we're
* not sure what, if anything, actually changed.
*/
if (this.cpu) this.cpu.updateDisplay(nUpdate);
if (this.panel) this.panel.updateDisplay(nUpdate);
if (this.cpu) this.cpu.updateDisplay(nUpdate || 0);
if (this.panel) this.panel.updateDisplay(nUpdate || 0);
};
/**

View file

@ -105,6 +105,8 @@ function CPUPDP11(parmsCPU, nCyclesDefault)
var nMultiplier = parmsCPU['multiplier'] || 1;
this.nDisplayCount = 0;
this.nDisplayLimit = 30;
this.nCyclesPerSecond = nCycles;
/*
@ -525,12 +527,17 @@ CPUPDP11.prototype.updateDisplays = function(nUpdate)
* However, this should be called via the Computer's updateDisplays() interface, not directly.
*
* @this {CPUPDP11}
* @param {number} [nUpdate] (1 for periodic, -1 for forced, 0 or undefined otherwise)
* @param {number} [nUpdate] (1 for periodic, -1 for forced, 0 otherwise)
*/
CPUPDP11.prototype.updateDisplay = function(nUpdate)
{
var controlSpeed = this.bindings["speed"];
if (controlSpeed) controlSpeed.textContent = this.getSpeedCurrent();
if (controlSpeed) {
if (nUpdate <= 0 || (this.nDisplayCount += nUpdate) >= this.nDisplayLimit) {
controlSpeed.textContent = this.getSpeedCurrent();
this.nDisplayCount = 0;
}
}
};
/**
@ -684,7 +691,7 @@ CPUPDP11.prototype.getSpeedCurrent = function()
/*
* TODO: Has toFixed() been "fixed" in all browsers (eg, IE) to return a rounded value now?
*/
return ((this.flags.running && this.mhz)? (this.mhz.toFixed(2) + "Mhz") : "Stopped");
return ((this.flags.running)? (this.mhz.toFixed(2) + "Mhz") : "Stopped");
};
/**

View file

@ -60,8 +60,8 @@ function PanelPDP11(parmsPanel)
* TODO: Add some UI for fDisplayLiveRegs (either an XML property, or a UI checkbox, or both).
*/
this.cLiveRegs = 0;
this.nPeriodicCount = 0;
this.nPeriodicLimit = 60;
this.nDisplayCount = 0;
this.nDisplayLimit = 60;
this.fDisplayLiveRegs = true;
/*
@ -968,7 +968,7 @@ PanelPDP11.prototype.setData = function(value, fActive)
* Called by the Computer component at intervals to update registers, LEDs, etc.
*
* @this {PanelPDP11}
* @param {number} [nUpdate] (< 0 for forced, > 0 for periodic, undefined otherwise)
* @param {number} [nUpdate] (< 0 for forced, > 0 for periodic, 0 otherwise)
*/
PanelPDP11.prototype.updateDisplay = function(nUpdate)
{
@ -985,7 +985,7 @@ PanelPDP11.prototype.updateDisplay = function(nUpdate)
* LEDs are considered cheap, register displays are not. So we'll skip the latter if this
* is a periodic update AND our periodic update counter hasn't reached the periodic update limit.
*/
if (!(nUpdate > 0 && (this.nPeriodicCount += nUpdate) < this.nPeriodicLimit)) {
if (nUpdate <= 0 || (this.nDisplayCount += nUpdate) >= this.nDisplayLimit) {
for (var i = 0; i < this.cpu.regsGen.length; i++) {
this.displayValue('R'+i, this.cpu.regsGen[i]);
}
@ -995,7 +995,7 @@ PanelPDP11.prototype.updateDisplay = function(nUpdate)
this.displayValue("ZF", (regPSW & PDP11.PSW.ZF)? 1 : 0, 1);
this.displayValue("VF", (regPSW & PDP11.PSW.VF)? 1 : 0, 1);
this.displayValue("CF", (regPSW & PDP11.PSW.CF)? 1 : 0, 1);
this.nPeriodicCount = 0;
this.nDisplayCount = 0;
}
/*