diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java index 7a8f500b..b12e0028 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/MainForm.java @@ -271,7 +271,7 @@ public String getDescription() { private final AtomicReference currentAnimationEncoder = new AtomicReference<>(); private final Motherboard board; private final ZxVideoStreamer videoStreamer; - private final Timer wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS, Duration.ofNanos(50000L)); + private final Timer wallClock; private final Runnable traceWindowsUpdater = new Runnable() { @Override public void run() { @@ -386,6 +386,14 @@ public void run() { public MainForm(final MainFormParameters parameters) { super(parameters.getTitle()); + + if (AppOptions.getInstance().isTryLessResources()) { + LOGGER.info("Less resources mode is active"); + this.wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS, Duration.ofNanos(50000L)); + } else { + this.wallClock = new Timer(TIMER_INT_DELAY_MILLISECONDS); + } + this.setUndecorated(parameters.isUndecorated()); Runtime.getRuntime().addShutdownHook(new Thread(this::doOnShutdown)); diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/ui/OptionsPanel.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/ui/OptionsPanel.java index 151c169b..8ca3df23 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/ui/OptionsPanel.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/ui/OptionsPanel.java @@ -72,9 +72,11 @@ public class OptionsPanel extends JTabbedPane { private JLabel labelCustomRomPath; private JLabel labelMacroCursorKeys; private JLabel labelTimingProfile; + private JLabel labelTryLessResources; private JLabel labelBorderWidth; private JLabel labelEmulateFFport; private JCheckBox checkGrabSound; + private JCheckBox checkTryLessResources; private JCheckBox checkInterlacedScan; private JCheckBox checkSoundSchemeACB; private JCheckBox checkSyncPaint; @@ -198,6 +200,7 @@ private void initComponents() { labelInterlacedScan = new JLabel(); labelOldTvFilter = new JLabel(); labelTimingProfile = new JLabel(); + labelTryLessResources = new JLabel(); labelBorderWidth = new JLabel(); checkInterlacedScan = new JCheckBox(); labelFfMpegPath = new JLabel(); @@ -235,6 +238,7 @@ private void initComponents() { checkAutoiCsForCursorKeys = new JCheckBox(); checkSyncPaint = new JCheckBox(); checkOldTvFilter = new JCheckBox(); + checkTryLessResources = new JCheckBox(); checkVkbdApart = new JCheckBox(); comboKeyboardLook = new JComboBox<>(VirtualKeyboardLook.values()); comboVolumeProfile = new JComboBox<>(VolumeProfile.values()); @@ -623,6 +627,20 @@ private void initComponents() { gridBagConstraints.anchor = GridBagConstraints.WEST; panelGeneral.add(comboTimingProfile, gridBagConstraints); + labelTryLessResources.setHorizontalAlignment(RIGHT); + labelTryLessResources.setText("Try use less resources:"); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 12; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + panelGeneral.add(labelTryLessResources, gridBagConstraints); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 12; + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = GridBagConstraints.WEST; + panelGeneral.add(checkTryLessResources, gridBagConstraints); + final JPanel panelKempston = new JPanel(new GridBagLayout()); panelKempston.setBorder(createTitledBorder("Kempston joystick")); @@ -753,6 +771,7 @@ public static final class DataContainer { public final boolean vkdApart; public final boolean autoCsForCursorKeys; public final boolean interlacedScan; + public final boolean tryLessResources; public final boolean syncPaint; public final boolean oldTvFilter; public final boolean emulateFFport; @@ -779,6 +798,7 @@ public DataContainer() { this.timingProfile = AppOptions.getInstance().getTimingProfile(); this.customRomPath = customRomPath == null ? "" : customRomPath; this.interlacedScan = AppOptions.getInstance().isInterlacedScan(); + this.tryLessResources = AppOptions.getInstance().isTryLessResources(); this.oldTvFilter = AppOptions.getInstance().isOldColorTvOnStart(); this.soundSchemeAcb = AppOptions.getInstance().isSoundChannelsACB(); this.autoCsForCursorKeys = AppOptions.getInstance().getAutoCsForCursorKeys(); @@ -820,6 +840,7 @@ public DataContainer(final OptionsPanel optionsPanel) { this.customRomPath = optionsPanel.textCustomRomPath.getText(); this.interlacedScan = optionsPanel.checkInterlacedScan.isSelected(); + this.tryLessResources = optionsPanel.checkTryLessResources.isSelected(); this.oldTvFilter = optionsPanel.checkOldTvFilter.isSelected(); this.syncPaint = optionsPanel.checkSyncPaint.isSelected(); @@ -860,6 +881,7 @@ public void store() { AppOptions.getInstance().setTimingProfile(this.timingProfile); AppOptions.getInstance().setBorderWidth(this.borderWidth); AppOptions.getInstance().setInterlacedScan(this.interlacedScan); + AppOptions.getInstance().setTryLessResources(this.tryLessResources); AppOptions.getInstance().setOldColorTvOnStart(this.oldTvFilter); AppOptions.getInstance().setAutoCsForCursorKeys(this.autoCsForCursorKeys); AppOptions.getInstance().setCustomRomPath(this.customRomPath); diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/AppOptions.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/AppOptions.java index af97f089..18320469 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/AppOptions.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/AppOptions.java @@ -218,10 +218,18 @@ public synchronized boolean isInterlacedScan() { return preferences.getBoolean(Option.INTERLACED_SCAN.name(), true); } + public synchronized boolean isTryLessResources() { + return preferences.getBoolean(Option.TRY_LESS_RESOURCES.name(), false); + } + public synchronized void setInterlacedScan(final boolean value) { preferences.putBoolean(Option.INTERLACED_SCAN.name(), value); } + public synchronized void setTryLessResources(final boolean value) { + preferences.putBoolean(Option.TRY_LESS_RESOURCES.name(), value); + } + public synchronized int getFrameRate() { return preferences.getInt(Option.STREAM_FRAMERATE.name(), 25); } @@ -537,7 +545,8 @@ public enum Option { PROTEK_JOYSTICK_VK_DOWN, PROTEK_JOYSTICK_VK_FIRE, ATTRIBUTE_PORT_FF, - ULAPLUS + ULAPLUS, + TRY_LESS_RESOURCES; } } diff --git a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/Timer.java b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/Timer.java index 0e279139..63b23864 100644 --- a/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/Timer.java +++ b/zxpoly-emul/src/main/java/com/igormaznitsa/zxpoly/utils/Timer.java @@ -26,9 +26,7 @@ public void next(final Duration delay) { } public void sleep() { - if (this.sleepDelay < 0L) { - Thread.onSpinWait(); - } else { + if (this.sleepDelay > 0L) { final long nanos = this.timeout - System.nanoTime(); if (nanos > this.sleepDelay) { LockSupport.parkNanos(this.sleepDelay);