From eb04e897083c9e7504f52461bec8a03beb958b74 Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Wed, 6 Mar 2024 00:17:03 -0600 Subject: [PATCH] Timed devices lock to parent timing where possible to avoid extra delays --- .../jace/src/main/java/jace/core/Device.java | 6 +++++ .../src/main/java/jace/core/TimedDevice.java | 27 ++++++++++++++----- .../java/jace/hardware/CardMockingboard.java | 5 ++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/Device.java b/Platform/Apple/tools/jace/src/main/java/jace/core/Device.java index 70fa455a..a7ad11f5 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/Device.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/Device.java @@ -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); diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java b/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java index eadc7644..901319cd 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/TimedDevice.java @@ -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; } } \ No newline at end of file diff --git a/Platform/Apple/tools/jace/src/main/java/jace/hardware/CardMockingboard.java b/Platform/Apple/tools/jace/src/main/java/jace/hardware/CardMockingboard.java index 1e3c2617..033aa569 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/hardware/CardMockingboard.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/hardware/CardMockingboard.java @@ -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