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;
};

View file

@ -910,7 +910,7 @@ Video8080.prototype.setFocus = function()
* getRefreshTime()
*
* @this {Video8080}
* @return {number}
* @return {number} (number of milliseconds per refresh)
*/
Video8080.prototype.getRefreshTime = function()
{

View file

@ -953,7 +953,7 @@ CPUPDP11.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.
@ -965,19 +965,22 @@ CPUPDP11.prototype.addTimer = function(callBack)
*
* Ideally, the only function that would use setTimeout() is runCPU(), while the rest of the components
* use setTimer(); however, due to legacy code (ie, code that predates these functions) and/or laziness,
* that's currently not the case. TODO: Fix.
* that may not be the case.
*
* @this {CPUPDP11}
* @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)
*/
CPUPDP11.prototype.setTimer = function(iTimer, ms)
CPUPDP11.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;
};

View file

@ -76,8 +76,8 @@ function DevicePDP11(parmsDevice)
};
this.kw11 = {
init: 0,
csr: 0
csr: 0,
timer: -1 // initBus() will initialize this timer ID
};
this.rk11 = {
@ -190,6 +190,12 @@ DevicePDP11.prototype.initBus = function(cmp, bus, cpu, dbg)
this.bus = bus;
this.cpu = cpu;
this.dbg = dbg;
var device = this;
this.kw11.timer = this.cpu.addTimer(function() {
device.kw11_interrupt();
});
switch(this.sDeviceName) {
case DevicePDP11.UNIBUS_NAME:
default:
@ -225,10 +231,7 @@ DevicePDP11.prototype.writeLKS = function(data, addr)
{
this.kw11.lks = data;
if (data & PDP11.KW11.LKS.INT_ENABLE) {
if (!this.kw11.init) {
setInterval(this.kw11_interrupt.bind(this), 25);
this.kw11.init = 1;
}
this.cpu.setTimer(this.kw11.timer, 1000/60);
}
this.kw11.lks = data & ~PDP11.KW11.LKS.MONITOR;
};
@ -713,6 +716,7 @@ DevicePDP11.prototype.kw11_interrupt = function()
this.kw11.lks |= PDP11.KW11.LKS.MONITOR;
if (this.kw11.lks & PDP11.KW11.LKS.INT_ENABLE) {
this.cpu.interrupt(PDP11.KW11.DELAY, PDP11.KW11.PRI, PDP11.KW11.VEC);
this.cpu.setTimer(this.kw11.timer, 1000/60);
}
};