Cleaned up the run loop, less complicated now, and video updates can drive themselves thanks to the new CPU timer functions

This commit is contained in:
Jeff Parsons 2016-08-23 22:41:45 -07:00
commit 244f0dba32
7 changed files with 451 additions and 495 deletions

View file

@ -430,6 +430,13 @@ Video8080.prototype.initBus = function(cmp, bus, cpu, dbg)
}
}
var video = this;
this.timerUpdateNext = this.cpu.addTimer(function() {
video.updateScreen();
});
this.cpu.setTimer(this.timerUpdateNext, this.getRefreshTime());
this.nUpdates = 0;
if (!this.sFontROM) this.setReady();
};
@ -797,7 +804,7 @@ Video8080.prototype.updateScrollOffset = function(bScroll)
* that update doesn't seem like a huge cause for concern.
*/
if (bScroll) {
this.updateScreen(-1);
this.updateScreen(true);
} else {
this.fSkipSingleCellUpdate = true;
}
@ -902,14 +909,14 @@ Video8080.prototype.setFocus = function()
};
/**
* getRefreshRate()
* getRefreshTime()
*
* @this {Video8080}
* @return {number}
*/
Video8080.prototype.getRefreshRate = function()
Video8080.prototype.getRefreshTime = function()
{
return Math.max(this.rateRefresh, this.rateInterrupt);
return 1000 / Math.max(this.rateRefresh, this.rateInterrupt);
};
/**
@ -1194,7 +1201,7 @@ Video8080.prototype.updateVT100 = function(fForced)
};
/**
* updateScreen(n)
* updateScreen(fForced)
*
* 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
@ -1205,22 +1212,20 @@ Video8080.prototype.updateVT100 = function(fForced)
* invalid value, we're assured that the next call to updateScreen() will redraw the entire (visible) video buffer.
*
* @this {Video8080}
* @param {number} n (where 0 <= n < getRefreshRate() for a normal update, or -1 for a forced update)
* @param {boolean} [fForced]
*/
Video8080.prototype.updateScreen = function(n)
Video8080.prototype.updateScreen = function(fForced)
{
var fClean;
var fUpdate = true;
var fForced = true;
if (n >= 0) {
fForced = false;
if (!fForced) {
if (this.rateInterrupt) {
/*
* TODO: Incorporate these hard-coded interrupt vector numbers into configuration blocks.
*/
if (this.rateInterrupt == 120) {
if (!(n & 1)) {
if (!(this.nUpdates & 1)) {
/*
* On even updates, call cpu.requestINTR(1), and also update our copy of the screen.
*/
@ -1248,13 +1253,15 @@ Video8080.prototype.updateScreen = function(n)
fUpdate = false;
}
}
this.cpu.setTimer(this.timerUpdateNext, this.getRefreshTime());
this.nUpdates++;
}
if (DEBUG && !fForced) {
var nCycles = this.cpu.getCycles();
this.nCyclesDelta = nCycles - this.nCyclesPrev;
this.nCyclesPrev = nCycles;
if (MAXDEBUG) this.printMessage("updateScreen(" + n + "): clean=" + fClean + ", update=" + fUpdate + ", cycles=" + this.nCyclesPrev + ", delta=" + this.nCyclesDelta);
if (MAXDEBUG) this.printMessage("updateScreen(false): clean=" + fClean + ", update=" + fUpdate + ", cycles=" + this.nCyclesPrev + ", delta=" + this.nCyclesDelta);
}
if (!fUpdate) {