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 0bc838fe..455c79ff 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/JaceUIController.java @@ -259,9 +259,10 @@ public class JaceUIController { } if (speedRatio >= 100.0) { Emulator.getComputer().getMotherboard().setMaxSpeed(true); - Motherboard.cpuPerClock = 10; + Emulator.getComputer().getMotherboard().setSpeedInPercentage(20000); +// Motherboard.cpuPerClock = 10; } else { - if (speedRatio > 25) { + if (speedRatio > 1000) { Motherboard.cpuPerClock = 2; } else { Motherboard.cpuPerClock = 1; @@ -391,11 +392,11 @@ public class JaceUIController { Map iconTTL = new ConcurrentHashMap<>(); - void addIndicator(Label icon) { + public void addIndicator(Label icon) { addIndicator(icon, 250); } - void addIndicator(Label icon, long TTL) { + public void addIndicator(Label icon, long TTL) { if (!iconTTL.containsKey(icon)) { Application.invokeLater(() -> { if (!notificationBox.getChildren().contains(icon)) { @@ -406,7 +407,7 @@ public class JaceUIController { trackTTL(icon, TTL); } - void removeIndicator(Label icon) { + public void removeIndicator(Label icon) { Application.invokeLater(() -> { notificationBox.getChildren().remove(icon); iconTTL.remove(icon); diff --git a/Platform/Apple/tools/jace/src/main/java/jace/apple2e/Apple2e.java b/Platform/Apple/tools/jace/src/main/java/jace/apple2e/Apple2e.java index 43ccc222..368f0fc2 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/apple2e/Apple2e.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/apple2e/Apple2e.java @@ -26,6 +26,7 @@ import jace.config.ConfigurableField; import jace.core.*; import jace.hardware.*; import jace.hardware.massStorage.CardMassStorage; +import jace.lawless.FPSMonitorDevice; import jace.lawless.LawlessVideo; import jace.state.Stateful; @@ -95,12 +96,16 @@ public class Apple2e extends Computer { public Cheats activeCheatEngine = null; public NoSlotClock clock; public ZipWarpAccelerator accelerator; + FPSMonitorDevice fpsCounters; + @ConfigurableField(name = "Show speed monitors", shortName = "showFps") + public boolean showSpeedMonitors = false; /** * Creates a new instance of Apple2e */ public Apple2e() { super(); + fpsCounters = new FPSMonitorDevice(this); try { setCpu(new MOS65C02(this)); setMotherboard(new Motherboard(this, null)); @@ -353,6 +358,10 @@ public class Apple2e extends Computer { for (Optional c : getMemory().getAllCards()) { c.ifPresent(newDeviceSet::add); } + if (showSpeedMonitors) { + newDeviceSet.add(fpsCounters); + } + motherboard.attach(); motherboard.setAllDevices(newDeviceSet); motherboard.reconfigure(); }); diff --git a/Platform/Apple/tools/jace/src/main/java/jace/apple2e/VideoDHGR.java b/Platform/Apple/tools/jace/src/main/java/jace/apple2e/VideoDHGR.java index 9cde29b0..ce1c6464 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/apple2e/VideoDHGR.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/apple2e/VideoDHGR.java @@ -74,6 +74,8 @@ public class VideoDHGR extends Video { initHgrDhgrTables(); initVideoWriters(); registerDirtyFlagChecks(); + currentTextWriter = textPage1; + currentGraphicsWriter = loresPage1; } // Take two consecutive bytes and double them, taking hi-bit into account diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/Computer.java b/Platform/Apple/tools/jace/src/main/java/jace/core/Computer.java index afdf994a..7a1b33b1 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/Computer.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/Computer.java @@ -21,6 +21,7 @@ package jace.core; import jace.config.ConfigurableField; import jace.config.InvokableAction; import jace.config.Reconfigurable; +import jace.lawless.FPSMonitorDevice; import jace.state.StateManager; import javafx.beans.property.BooleanProperty; import javafx.beans.property.SimpleBooleanProperty; 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 4a17d754..ea86ecf1 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 @@ -42,6 +42,7 @@ public abstract class Device implements Reconfigurable { protected Computer computer; private final MutableSet children; + private Device[] childrenArray = new Device[0]; private Device() { children = Sets.mutable.empty(); @@ -70,6 +71,7 @@ public abstract class Device implements Reconfigurable { if (isAttached) { d.attach(); } + childrenArray = children.toArray(new Device[0]); } public void removeChildDevice(Device d) { @@ -81,6 +83,7 @@ public abstract class Device implements Reconfigurable { if (isAttached) { d.detach(); } + childrenArray = children.toArray(new Device[0]); } public void addAllDevices(Iterable devices) { @@ -110,7 +113,9 @@ public abstract class Device implements Reconfigurable { public void doTick() { if (isRunning()) { - children.forEach(Device::doTick); + for (Device d : childrenArray) { + d.doTick(); + } if (waitCycles > 0) { waitCycles--; return; 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 4bc90007..9b20bcb6 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 @@ -23,9 +23,6 @@ import jace.apple2e.Speaker; import jace.config.ConfigurableField; import java.util.HashSet; -import java.util.Optional; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Motherboard is the heart of the computer. It can have a list of cards @@ -79,11 +76,16 @@ public class Motherboard extends TimedDevice { return "mb"; } @ConfigurableField(category = "advanced", shortName = "cpuPerClock", name = "CPU per clock", defaultValue = "1", description = "Number of CPU cycles per clock cycle (normal = 1)") - public static int cpuPerClock = 4; + public static int cpuPerClock = 1; public int clockCounter = 1; @Override public void tick() { + // Extra CPU cycles requested, other devices are called by the TimedDevice abstraction + for (int i=1; i < cpuPerClock; i++) { + computer.getCpu().doTick(); + } + /* try { clockCounter--; computer.getCpu().doTick(); @@ -100,6 +102,7 @@ public class Motherboard extends TimedDevice { System.out.print("!"); Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, t); } +*/ } // From the holy word of Sather 3:5 (Table 3.1) :-) // This average speed averages in the "long" cycles @@ -137,6 +140,7 @@ public class Motherboard extends TimedDevice { System.out.println("Speaker not enabled, leaving it off."); } }); + adjustRelativeSpeeds(); } HashSet accelorationRequestors = new HashSet<>(); @@ -151,4 +155,14 @@ public class Motherboard extends TimedDevice { disableTempMaxSpeed(); } } + + void adjustRelativeSpeeds() { + if (isMaxSpeed()) { + computer.getVideo().setWaitPerCycle(8); + } else if (getSpeedInHz() > SPEED) { + computer.getVideo().setWaitPerCycle(getSpeedInHz()/SPEED); + } else { + computer.getVideo().setWaitPerCycle(0); + } + } } 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 76d4665e..42d791cf 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 @@ -100,7 +100,9 @@ public abstract class TimedDevice extends Device { hasStopped = true; LockSupport.parkNanos(1000); } - resync(); + if (!maxspeed) { + resync(); + } } hasStopped = true; System.out.println("Worker thread for " + getDeviceName() + " stopped"); @@ -171,10 +173,8 @@ public abstract class TimedDevice extends Device { protected void resync() { if (++cycleTimer >= cyclesPerInterval) { - if (maxspeed || tempSpeedDuration > 0) { - if (tempSpeedDuration > 0) { - tempSpeedDuration -= cyclesPerInterval; - } + if (tempSpeedDuration > 0) { + tempSpeedDuration -= cyclesPerInterval; resetSyncTimer(); return; } diff --git a/Platform/Apple/tools/jace/src/main/java/jace/core/Video.java b/Platform/Apple/tools/jace/src/main/java/jace/core/Video.java index 5fbd01fe..29b3beea 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/core/Video.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/core/Video.java @@ -156,6 +156,8 @@ public abstract class Video extends Device { @Override public void tick() { + addWaitCycles(waitsPerCycle); + addWaitCycles((int) motherboardAdjustedWaitsPerCycle); setScannerLocation(currentWriter.getYOffset(y)); setFloatingBus(computer.getMemory().readRaw(scannerAddress + x)); if (hPeriod > 0) { @@ -232,7 +234,6 @@ public abstract class Video extends Device { lineDirty = true; currentWriter.displayByte(video, x, y, textOffset[y], hiresOffset[y]); } - setWaitCycles(waitsPerCycle); doPostDraw(); } @@ -294,4 +295,10 @@ public abstract class Video extends Device { public Image getFrameBuffer() { return visible; } + + long motherboardAdjustedWaitsPerCycle = 0; + public void setWaitPerCycle(long l) { + motherboardAdjustedWaitsPerCycle = Math.max(0,l); + System.out.println("Adjusting video rendering speed to 1/"+(l+1)); + } } diff --git a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java index 3c08d76b..326f0bb9 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessComputer.java @@ -33,7 +33,7 @@ public class LawlessComputer extends Apple2e { super(); motherboard.whileSuspended(this::initLawlessLegendsConfiguration); } - + private void initLawlessLegendsConfiguration() { reconfigure(); // Required before anything so that memory is initialized this.cheatEngine.setValue(LawlessHacks.class); diff --git a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessVideo.java b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessVideo.java index 6b256096..4327f5f2 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessVideo.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/lawless/LawlessVideo.java @@ -78,6 +78,7 @@ public class LawlessVideo extends VideoNTSC { public LawlessVideo(Computer computer) { super(computer); + this.vblankStart(); } public void setEngine(RenderEngine e) { diff --git a/Platform/Apple/tools/jace/src/main/resources/fxml/JaceUI.fxml b/Platform/Apple/tools/jace/src/main/resources/fxml/JaceUI.fxml index 0fba4b16..66a3669f 100644 --- a/Platform/Apple/tools/jace/src/main/resources/fxml/JaceUI.fxml +++ b/Platform/Apple/tools/jace/src/main/resources/fxml/JaceUI.fxml @@ -11,7 +11,7 @@ - +