From c50ea6ec77323336e04113bbe31d5bb8db326d3f Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Thu, 1 Feb 2018 09:09:18 -0600 Subject: [PATCH] cleaned up how speed is managed in the app --- .../src/main/java/jace/JaceUIController.java | 6 +-- .../src/main/java/jace/cheat/MetaCheat.java | 2 +- .../src/main/java/jace/core/Motherboard.java | 5 +- .../src/main/java/jace/core/TimedDevice.java | 49 ++++++++++++++----- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java b/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java index 880d45c1..02ebec92 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java @@ -257,7 +257,7 @@ public class JaceUIController { Emulator.logic.speedSetting = (int) speed; double speedRatio = convertSpeedToRatio(speed); if (speedRatio > 100.0) { - Emulator.computer.getMotherboard().maxspeed = true; + Emulator.computer.getMotherboard().setMaxSpeed(true); Motherboard.cpuPerClock = 3; } else { if (speedRatio > 25) { @@ -265,8 +265,8 @@ public class JaceUIController { } else { Motherboard.cpuPerClock = 1; } - Emulator.computer.getMotherboard().maxspeed = false; - Emulator.computer.getMotherboard().speedRatio = (int) (speedRatio * 100); + Emulator.computer.getMotherboard().setMaxSpeed(false); + Emulator.computer.getMotherboard().setSpeedInPercentage((int) (speedRatio * 100)); } Emulator.computer.getMotherboard().reconfigure(); } diff --git a/Platform/Apple/tools/jace/src/main/java/jace/cheat/MetaCheat.java b/Platform/Apple/tools/jace/src/main/java/jace/cheat/MetaCheat.java index dc4a46ec..d03ddcbf 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/cheat/MetaCheat.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/cheat/MetaCheat.java @@ -305,7 +305,7 @@ public class MetaCheat extends Cheats { } int fadeCounter = 0; - int FADE_TIMER_VALUE = (int) (Emulator.computer.getMotherboard().cyclesPerSecond / 60); + int FADE_TIMER_VALUE = (int) (Emulator.computer.getMotherboard().getSpeedInHz() / 60); @Override public void tick() { diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java b/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java index c863ed25..bbf6f1b1 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/Motherboard.java @@ -65,6 +65,9 @@ public class Motherboard extends TimedDevice { if (oldMotherboard != null) { miscDevices.addAll(oldMotherboard.miscDevices); speaker = oldMotherboard.speaker; + accelorationRequestors.addAll(oldMotherboard.accelorationRequestors); + setSpeedInHz(oldMotherboard.getSpeedInHz()); + setMaxSpeed(oldMotherboard.isMaxSpeed()); } } @@ -147,7 +150,7 @@ public class Motherboard extends TimedDevice { resume(); } } - static HashSet accelorationRequestors = new HashSet<>(); + HashSet accelorationRequestors = new HashSet<>(); public void requestSpeed(Object requester) { accelorationRequestors.add(requester); 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 d2be5295..a0050962 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 @@ -21,24 +21,25 @@ package jace.core; import jace.config.ConfigurableField; /** - * A timed device is a device which executes so many ticks in a given time - * interval. This is the core of the emulator timing mechanics. + * A timed device is a device which executes so many ticks in a given time interval. This is the core of the emulator + * timing mechanics. * - * @author Brendan Robert (BLuRry) brendan.robert@gmail.com + * @author Brendan Robert (BLuRry) brendan.robert@gmail.com */ public abstract class TimedDevice extends Device { /** * Creates a new instance of TimedDevice + * * @param computer */ public TimedDevice(Computer computer) { super(computer); - setSpeed(cyclesPerSecond); + setSpeedInHz(cyclesPerSecond); } @ConfigurableField(name = "Speed", description = "(Percentage)") public int speedRatio = 100; - public long cyclesPerSecond = defaultCyclesPerSecond(); + private long cyclesPerSecond = defaultCyclesPerSecond(); @ConfigurableField(name = "Max speed") public boolean maxspeed = false; @@ -114,13 +115,44 @@ public abstract class TimedDevice extends Device { long cyclesPerInterval; // How many cycles to wait until a pause interval long nextSync; // When was the last pause? - public final void setSpeed(long cyclesPerSecond) { + public final int getSpeedRatio() { + return speedRatio; + } + + public final void setMaxSpeed(boolean enabled) { + maxspeed = enabled; + if (!enabled) { + disableTempMaxSpeed(); + } + } + + public final boolean isMaxSpeed() { + return maxspeed; + } + + public final long getSpeedInHz() { + return cyclesPerInterval * 100L; + } + + public final void setSpeedInHz(long cyclesPerSecond) { +// System.out.println("Raw set speed for " + getName() + " to " + cyclesPerSecond + "hz"); + speedRatio = (int) Math.round(cyclesPerSecond * 100.0 / defaultCyclesPerSecond()); cyclesPerInterval = cyclesPerSecond / 100L; nanosPerInterval = (long) (cyclesPerInterval * NANOS_PER_SECOND / cyclesPerSecond); // System.out.println("Will pause " + nanosPerInterval + " nanos every " + cyclesPerInterval + " cycles"); cycleTimer = 0; resetSyncTimer(); } + + public final void setSpeedInPercentage(int ratio) { +// System.out.println("Setting " + getName() + " speed ratio to " + speedRatio); + cyclesPerSecond = defaultCyclesPerSecond() * ratio / 100; + if (cyclesPerSecond == 0) { + cyclesPerSecond = defaultCyclesPerSecond(); + } + setSpeedInHz(cyclesPerSecond); + } + long skip = 0; long wait = 0; @@ -171,11 +203,6 @@ public abstract class TimedDevice extends Device { @Override public void reconfigure() { - cyclesPerSecond = defaultCyclesPerSecond() * speedRatio / 100; - if (cyclesPerSecond == 0) { - cyclesPerSecond = defaultCyclesPerSecond(); - } - setSpeed(cyclesPerSecond); } public abstract long defaultCyclesPerSecond();