Updated addTimer() interface to include an ID; cleaned up how the CPU tracks the base speed, current speed, and target speed

This commit is contained in:
Jeff Parsons 2017-08-07 13:58:41 -07:00 committed by Jeff Parsons
commit e5a9b01dde
18 changed files with 2403 additions and 2387 deletions

View file

@ -180,7 +180,73 @@ class ChipSet extends Component {
* HDC calls setCMOSDriveType() or RAM calls addCMOSMemory()), the CMOS will be ready to take their calls.
*/
this.reset(true);
}
/**
* initBus(cmp, bus, cpu, dbg)
*
* @this {ChipSet}
* @param {Computer} cmp
* @param {Bus} bus
* @param {X86CPU} cpu
* @param {DebuggerX86} dbg
*/
initBus(cmp, bus, cpu, dbg)
{
this.bus = bus;
this.cpu = cpu;
this.dbg = dbg;
this.cmp = cmp;
this.fpu = cmp.getMachineComponent("FPU");
this.setDIPSwitches(ChipSet.SWITCH_TYPE.FPU, this.fpu?1:0, true);
this.kbd = cmp.getMachineComponent("Keyboard");
/*
* This divisor is invariant, so we calculate it as soon as we're able to query the CPU's base speed.
*/
this.nTicksDivisor = (cpu.getBaseCyclesPerSecond() / ChipSet.TIMER_TICKS_PER_SEC);
bus.addPortInputTable(this, ChipSet.aPortInput);
bus.addPortOutputTable(this, ChipSet.aPortOutput);
if (this.model < ChipSet.MODEL_5170) {
if (this.model != ChipSet.MODEL_ATT_6300) {
bus.addPortInputTable(this, ChipSet.aPortInput5150);
bus.addPortOutputTable(this, ChipSet.aPortOutput5150);
} else {
bus.addPortInputTable(this, ChipSet.aPortInput6300);
bus.addPortOutputTable(this, ChipSet.aPortOutput6300);
}
} else {
bus.addPortInputTable(this, ChipSet.aPortInput5170);
bus.addPortOutputTable(this, ChipSet.aPortOutput5170);
if (DESKPRO386 && (this.model|0) == ChipSet.MODEL_COMPAQ_DESKPRO386) {
bus.addPortInputTable(this, ChipSet.aPortInputDeskPro386);
bus.addPortOutputTable(this, ChipSet.aPortOutputDeskPro386);
}
}
if (DEBUGGER) {
if (dbg) {
var chipset = this;
/*
* TODO: Add more "dumpers" (eg, for DMA, RTC, 8042, etc)
*/
dbg.messageDump(Messages.PIC, function onDumpPIC() {
chipset.dumpPIC();
});
dbg.messageDump(Messages.TIMER, function onDumpTimer(asArgs) {
chipset.dumpTimer(asArgs);
});
if (this.model >= ChipSet.MODEL_5170) {
dbg.messageDump(Messages.CMOS, function onDumpCMOS() {
chipset.dumpCMOS();
});
}
}
cpu.addIntNotify(Interrupts.RTC, this.intBIOSRTC.bind(this));
}
this.setReady();
}
@ -221,70 +287,6 @@ class ChipSet extends Component {
return false;
}
/**
* initBus(cmp, bus, cpu, dbg)
*
* @this {ChipSet}
* @param {Computer} cmp
* @param {Bus} bus
* @param {X86CPU} cpu
* @param {DebuggerX86} dbg
*/
initBus(cmp, bus, cpu, dbg)
{
this.bus = bus;
this.cpu = cpu;
this.dbg = dbg;
this.cmp = cmp;
this.fpu = cmp.getMachineComponent("FPU");
this.setDIPSwitches(ChipSet.SWITCH_TYPE.FPU, this.fpu?1:0, true);
this.kbd = cmp.getMachineComponent("Keyboard");
/*
* This divisor is invariant, so we calculate it as soon as we're able to query the CPU's base speed.
*/
this.nTicksDivisor = (cpu.getCyclesPerSecond() / ChipSet.TIMER_TICKS_PER_SEC);
bus.addPortInputTable(this, ChipSet.aPortInput);
bus.addPortOutputTable(this, ChipSet.aPortOutput);
if (this.model < ChipSet.MODEL_5170) {
if (this.model != ChipSet.MODEL_ATT_6300) {
bus.addPortInputTable(this, ChipSet.aPortInput5150);
bus.addPortOutputTable(this, ChipSet.aPortOutput5150);
} else {
bus.addPortInputTable(this, ChipSet.aPortInput6300);
bus.addPortOutputTable(this, ChipSet.aPortOutput6300);
}
} else {
bus.addPortInputTable(this, ChipSet.aPortInput5170);
bus.addPortOutputTable(this, ChipSet.aPortOutput5170);
if (DESKPRO386 && (this.model|0) == ChipSet.MODEL_COMPAQ_DESKPRO386) {
bus.addPortInputTable(this, ChipSet.aPortInputDeskPro386);
bus.addPortOutputTable(this, ChipSet.aPortOutputDeskPro386);
}
}
if (DEBUGGER) {
if (dbg) {
var chipset = this;
/*
* TODO: Add more "dumpers" (eg, for DMA, RTC, 8042, etc)
*/
dbg.messageDump(Messages.PIC, function onDumpPIC() {
chipset.dumpPIC();
});
dbg.messageDump(Messages.TIMER, function onDumpTimer(asArgs) {
chipset.dumpTimer(asArgs);
});
dbg.messageDump(Messages.CMOS, function onDumpCMOS() {
chipset.dumpCMOS();
});
}
cpu.addIntNotify(Interrupts.RTC, this.intBIOSRTC.bind(this));
}
}
/**
* powerUp(data, fRepower)
*
@ -634,7 +636,7 @@ class ChipSet extends Component {
{
this.nRTCCyclesLastUpdate = this.cpu.getCycles(this.fScaleTimers);
this.nRTCPeriodsPerSecond = 1024;
this.nRTCCyclesPerPeriod = Math.floor(this.cpu.getCyclesPerSecond() / this.nRTCPeriodsPerSecond);
this.nRTCCyclesPerPeriod = Math.floor(this.cpu.getBaseCyclesPerSecond() / this.nRTCPeriodsPerSecond);
this.setRTCCycleLimit();
}
@ -672,16 +674,15 @@ class ChipSet extends Component {
}
/**
* setRTCCycleLimit(nCycles)
* setRTCCycleLimit()
*
* This should be called when PIE becomes set in STATUSB (and whenever PF is cleared in STATUSC while PIE is still set).
*
* @this {ChipSet}
* @param {number} [nCycles]
*/
setRTCCycleLimit(nCycles)
setRTCCycleLimit()
{
if (nCycles === undefined) nCycles = this.nRTCCyclesPerPeriod;
var nCycles = this.nRTCCyclesPerPeriod;
this.nRTCCyclesNextUpdate = this.cpu.getCycles(this.fScaleTimers) + nCycles;
if (this.abCMOSData[ChipSet.CMOS.ADDR.STATUSB] & ChipSet.CMOS.STATUSB.PIE) {
this.cpu.setBurstCycles(nCycles);
@ -695,7 +696,7 @@ class ChipSet extends Component {
*/
updateRTCTime()
{
var nCyclesPerSecond = this.cpu.getCyclesPerSecond();
var nCyclesPerSecond = this.cpu.getBaseCyclesPerSecond();
var nCyclesUpdate = this.cpu.getCycles(this.fScaleTimers);
/*
@ -3412,7 +3413,7 @@ class ChipSet extends Component {
* For the original MODEL_5170, the number of cycles per tick is approximately 6,000,000 / 1,193,181,
* or 5.028575, so we can no longer always divide cycles by 4 with a simple right-shift by 2. The proper
* divisor (eg, 4 for MODEL_5150 and MODEL_5160, 5 for MODEL_5170, etc) is nTicksDivisor, which initBus()
* calculates using the base CPU speed returned by cpu.getCyclesPerSecond().
* calculates using the base CPU speed returned by cpu.getBaseCyclesPerSecond().
*/
var ticksElapsed = ((nCycles - timer.nCyclesStart) / this.nTicksDivisor) | 0;