Use CPU timer functions (instead of browser timeout/interval functions) to control device interrupts/timeouts

This commit is contained in:
Jeff 2016-09-26 20:34:31 -07:00 committed by Jeff Parsons
commit b2294e2293
8 changed files with 332 additions and 321 deletions

View file

@ -950,7 +950,7 @@ CPU8080.prototype.addTimer = function(callBack)
};
/**
* setTimer(iTimer, ms)
* setTimer(iTimer, ms, fReset)
*
* Using the timer index from a previous addTimer() call, this sets that timer to fire after the
* specified number of milliseconds.
@ -967,14 +967,17 @@ CPU8080.prototype.addTimer = function(callBack)
* @this {CPU8080}
* @param {number} iTimer
* @param {number} ms (converted into a cycle countdown internally)
* @param {boolean} [fReset] (true if the timer should be reset even if already armed)
* @return {number} (number of cycles used to arm timer, or -1 if error)
*/
CPU8080.prototype.setTimer = function(iTimer, ms)
CPU8080.prototype.setTimer = function(iTimer, ms, fReset)
{
var nCycles = -1;
if (iTimer >= 0 && iTimer < this.aTimers.length) {
nCycles = this.getMSCycles(ms);
this.aTimers[iTimer][0] = nCycles;
if (fReset || this.aTimers[iTimer][0] < 0) {
nCycles = this.getMSCycles(ms);
this.aTimers[iTimer][0] = nCycles;
}
}
return nCycles;
};