Machine states now save/restore the CPU's running state

This commit is contained in:
Jeff Parsons 2017-06-27 14:08:16 -07:00 • committed by Jeff Parsons
commit 754a4a4027
10 changed files with 977 additions and 949 deletions

View file

@ -1819,16 +1819,24 @@ class X86CPU extends CPU {
}
/**
* save()
* save(fRunning)
*
* This implements save support for the X86 component.
*
* NOTE: When the Computer starts issuing powerDown() calls, it always calls the CPU first, and the CPU's
* powerDown() handler has the added responsibility of:
*
* 1) recording whether or not the CPU is currently running
* 2) stopping the CPU if the powerDown is part of a shutDown
* 3) passing the original running state to us
*
* UPDATES: The current speed multiplier from getSpeed() is now saved in group #3, so that your speed is preserved.
*
* @this {X86CPU}
* @param {boolean} [fRunning]
* @return {Object|null}
*/
save()
save(fRunning)
{
var state = new State(this);
state.set(0, [this.regEAX, this.regEBX, this.regECX, this.regEDX, this.getSP(), this.regEBP, this.regESI, this.regEDI]);
@ -1839,7 +1847,7 @@ class X86CPU extends CPU {
}
state.set(1, a);
state.set(2, [this.segData.sName, this.segStack.sName, this.opFlags, this.opPrefixes, this.intFlags, this.regEA, this.regEAWrite]);
state.set(3, [0, this.nTotalCycles, this.getSpeed()]);
state.set(3, [0, this.nTotalCycles, this.getSpeed(), fRunning]);
state.set(4, this.bus.saveMemory(this.isPagingEnabled()));
return state.data();
}
@ -1911,7 +1919,10 @@ class X86CPU extends CPU {
a = data[3]; // a[0] was previously nBurstDivisor (no longer used)
this.nTotalCycles = a[1];
this.setSpeed(a[2]); // if we're restoring an old state that doesn't contain a value from getSpeed(), that's OK; setSpeed() checks for an undefined value
this.setSpeed(a[2]); // old states didn't contain a value from getSpeed(), but setSpeed() checks
if (a[3] != null) { // less old states didn't preserve the original running state, so we must check it
this.flags.autoStart = a[3];
}
return fRestored;
}