mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-08-15 06:27:24 +00:00
Timed devices lock to parent timing where possible to avoid extra delays
This commit is contained in:
@@ -65,10 +65,16 @@ public abstract class Device implements Reconfigurable {
|
|||||||
return _ram;
|
return _ram;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Device parentDevice = null;
|
||||||
|
public Device getParent() {
|
||||||
|
return parentDevice;
|
||||||
|
}
|
||||||
|
|
||||||
public void addChildDevice(Device d) {
|
public void addChildDevice(Device d) {
|
||||||
if (d == null || children.contains(d) || d.equals(this)) {
|
if (d == null || children.contains(d) || d.equals(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
d.parentDevice = this;
|
||||||
children.add(d);
|
children.add(d);
|
||||||
d.attach();
|
d.attach();
|
||||||
childrenArray = children.toArray(Device[]::new);
|
childrenArray = children.toArray(Device[]::new);
|
||||||
|
@@ -169,20 +169,33 @@ public abstract class TimedDevice extends Device {
|
|||||||
return NTSC_1MHZ;
|
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() {
|
protected Long calculateResyncDelay() {
|
||||||
if (!isMaxSpeed() && ++cycleTimer >= cyclesPerInterval) {
|
if (++cycleTimer < cyclesPerInterval) {
|
||||||
cycleTimer = 0;
|
return null;
|
||||||
|
}
|
||||||
|
cycleTimer = 0;
|
||||||
|
if (isMaxSpeed() || useParentTiming()) {
|
||||||
if (tempSpeedDuration > 0) {
|
if (tempSpeedDuration > 0) {
|
||||||
tempSpeedDuration -= cyclesPerInterval;
|
tempSpeedDuration -= cyclesPerInterval;
|
||||||
if (tempSpeedDuration <= 0) {
|
if (tempSpeedDuration <= 0) {
|
||||||
disableTempMaxSpeed();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -276,7 +276,6 @@ public class CardMockingboard extends Card {
|
|||||||
public void resume() {
|
public void resume() {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
System.out.println("Resuming Mockingboard");
|
System.out.println("Resuming Mockingboard");
|
||||||
Thread.dumpStack();
|
|
||||||
}
|
}
|
||||||
if (!activatedAfterReset) {
|
if (!activatedAfterReset) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -300,7 +299,9 @@ public class CardMockingboard extends Card {
|
|||||||
}
|
}
|
||||||
idleTicks = 0;
|
idleTicks = 0;
|
||||||
super.resume();
|
super.resume();
|
||||||
System.out.println("Resuming Mockingboard: resume completed");
|
if (DEBUG) {
|
||||||
|
System.out.println("Resuming Mockingboard: resume completed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user