Timed devices lock to parent timing where possible to avoid extra delays

This commit is contained in:
Brendan Robert 2024-03-06 00:17:03 -06:00
parent dcf4638e1e
commit eb04e89708
3 changed files with 29 additions and 9 deletions

View File

@ -65,10 +65,16 @@ public abstract class Device implements Reconfigurable {
return _ram;
}
Device parentDevice = null;
public Device getParent() {
return parentDevice;
}
public void addChildDevice(Device d) {
if (d == null || children.contains(d) || d.equals(this)) {
return;
}
d.parentDevice = this;
children.add(d);
d.attach();
childrenArray = children.toArray(Device[]::new);

View File

@ -169,20 +169,33 @@ public abstract class TimedDevice extends Device {
return NTSC_1MHZ;
}
private boolean useParentTiming() {
if (getParent() != null && getParent() instanceof TimedDevice) {
TimedDevice pd = (TimedDevice) getParent();
if (pd.useParentTiming() || (!pd.isMaxSpeed() && pd.getSpeedInHz() <= getSpeedInHz())) {
return true;
}
}
return false;
}
protected Long calculateResyncDelay() {
if (!isMaxSpeed() && ++cycleTimer >= cyclesPerInterval) {
cycleTimer = 0;
if (++cycleTimer < cyclesPerInterval) {
return null;
}
cycleTimer = 0;
if (isMaxSpeed() || useParentTiming()) {
if (tempSpeedDuration > 0) {
tempSpeedDuration -= cyclesPerInterval;
if (tempSpeedDuration <= 0) {
disableTempMaxSpeed();
}
} else {
long retVal = nextSync;
nextSync = Math.min(nextSync + nanosPerInterval, System.nanoTime() + nanosPerInterval * 2); // Avoid drift (but not too much!
return retVal;
}
nextSync += nanosPerInterval;
return null;
}
return null;
long retVal = nextSync;
nextSync = Math.min(nextSync + nanosPerInterval, System.nanoTime() + nanosPerInterval * 2); // Avoid drift (but not too much!
return retVal;
}
}

View File

@ -276,7 +276,6 @@ public class CardMockingboard extends Card {
public void resume() {
if (DEBUG) {
System.out.println("Resuming Mockingboard");
Thread.dumpStack();
}
if (!activatedAfterReset) {
if (DEBUG) {
@ -300,7 +299,9 @@ public class CardMockingboard extends Card {
}
idleTicks = 0;
super.resume();
System.out.println("Resuming Mockingboard: resume completed");
if (DEBUG) {
System.out.println("Resuming Mockingboard: resume completed");
}
}
@Override