diff --git a/distribution/ReleaseNotes.txt b/distribution/ReleaseNotes.txt index 4e6e6728b..1ab673b98 100644 --- a/distribution/ReleaseNotes.txt +++ b/distribution/ReleaseNotes.txt @@ -3,6 +3,7 @@ Release Notes Head, planned as v0.25 - move the "lib" folder from the "examples" folder to the root folder. - Reordering of the cells in the K-Map +- Counters are able to act as program counters via the remote interface. - 74193 was added v0.24, released on 1. Feb. 2020 diff --git a/src/main/java/de/neemann/digital/core/memory/Counter.java b/src/main/java/de/neemann/digital/core/memory/Counter.java index 681a76174..89179f35d 100644 --- a/src/main/java/de/neemann/digital/core/memory/Counter.java +++ b/src/main/java/de/neemann/digital/core/memory/Counter.java @@ -14,7 +14,7 @@ import static de.neemann.digital.core.element.PinInfo.input; /** * A simple counter. */ -public class Counter extends Node implements Element { +public class Counter extends Node implements Element, ProgramCounter { /** * The counters {@link ElementTypeDescription} @@ -25,13 +25,15 @@ public class Counter extends Node implements Element { .addAttribute(Keys.BITS) .addAttribute(Keys.INVERTER_CONFIG) .addAttribute(Keys.LABEL) - .addAttribute(Keys.VALUE_IS_PROBE); + .addAttribute(Keys.VALUE_IS_PROBE) + .addAttribute(Keys.IS_PROGRAM_COUNTER); private final ObservableValue out; private final ObservableValue ovf; private final long maxValue; private final boolean probe; private final String label; + private final boolean isProgramCounter; private ObservableValue clockIn; private ObservableValue clrIn; private ObservableValue enable; @@ -52,6 +54,7 @@ public class Counter extends Node implements Element { maxValue = Bits.mask(bits); probe = attributes.get(Keys.VALUE_IS_PROBE); label = attributes.getLabel(); + isProgramCounter = attributes.get(Keys.IS_PROGRAM_COUNTER); } @Override @@ -92,7 +95,6 @@ public class Counter extends Node implements Element { return ovs(out, ovf); } - @Override public void registerNodes(Model model) { super.registerNodes(model); @@ -105,4 +107,13 @@ public class Counter extends Node implements Element { })); } + @Override + public boolean isProgramCounter() { + return isProgramCounter; + } + + @Override + public long getProgramCounter() { + return counter; + } } diff --git a/src/main/java/de/neemann/digital/core/memory/CounterPreset.java b/src/main/java/de/neemann/digital/core/memory/CounterPreset.java index 498dd0042..eae4b1450 100644 --- a/src/main/java/de/neemann/digital/core/memory/CounterPreset.java +++ b/src/main/java/de/neemann/digital/core/memory/CounterPreset.java @@ -17,7 +17,7 @@ import static de.neemann.digital.core.element.PinInfo.input; /** * A simple counter. */ -public class CounterPreset extends Node implements Element { +public class CounterPreset extends Node implements Element, ProgramCounter { /** * The counters {@link ElementTypeDescription} @@ -35,7 +35,8 @@ public class CounterPreset extends Node implements Element { .addAttribute(Keys.MAX_VALUE) .addAttribute(Keys.INVERTER_CONFIG) .addAttribute(Keys.LABEL) - .addAttribute(Keys.VALUE_IS_PROBE); + .addAttribute(Keys.VALUE_IS_PROBE) + .addAttribute(Keys.IS_PROGRAM_COUNTER); private final ObservableValue out; private final ObservableValue ovf; @@ -43,6 +44,7 @@ public class CounterPreset extends Node implements Element { private final boolean probe; private final String label; private final int bits; + private final boolean isProgramCounter; private ObservableValue clockIn; private ObservableValue clrIn; private ObservableValue enable; @@ -72,6 +74,7 @@ public class CounterPreset extends Node implements Element { probe = attributes.get(Keys.VALUE_IS_PROBE); label = attributes.getLabel(); + isProgramCounter = attributes.get(Keys.IS_PROGRAM_COUNTER); } @Override @@ -145,4 +148,13 @@ public class CounterPreset extends Node implements Element { })); } + @Override + public boolean isProgramCounter() { + return isProgramCounter; + } + + @Override + public long getProgramCounter() { + return counter; + } } diff --git a/src/main/java/de/neemann/digital/core/memory/ProgramCounter.java b/src/main/java/de/neemann/digital/core/memory/ProgramCounter.java new file mode 100644 index 000000000..6ff0c8b58 --- /dev/null +++ b/src/main/java/de/neemann/digital/core/memory/ProgramCounter.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2020 Helmut Neemann. + * Use of this source code is governed by the GPL v3 license + * that can be found in the LICENSE file. + */ +package de.neemann.digital.core.memory; + +/** + * This interface is implemented by all components which are able to act as a program counter. + */ +public interface ProgramCounter { + + /** + * @return true if this component is used as the program counter + */ + boolean isProgramCounter(); + + /** + * @return the value of the program counter + */ + long getProgramCounter(); + +} diff --git a/src/main/java/de/neemann/digital/core/memory/Register.java b/src/main/java/de/neemann/digital/core/memory/Register.java index b2fc4b7eb..99f23166c 100644 --- a/src/main/java/de/neemann/digital/core/memory/Register.java +++ b/src/main/java/de/neemann/digital/core/memory/Register.java @@ -17,7 +17,7 @@ import static de.neemann.digital.core.element.PinInfo.input; /** * A simple register. */ -public class Register extends Node implements Element, Countable { +public class Register extends Node implements Element, Countable, ProgramCounter { /** * The registers {@link ElementTypeDescription} @@ -92,17 +92,13 @@ public class Register extends Node implements Element, Countable { })); } - /** - * @return true if this register is the program counter - */ + @Override public boolean isProgramCounter() { return isProgramCounter; } - /** - * @return the value of this register - */ - public long getValue() { + @Override + public long getProgramCounter() { return value; } diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index b95a19aca..97f0cb42a 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -15,7 +15,7 @@ import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.Keys; import de.neemann.digital.core.io.Button; import de.neemann.digital.core.io.*; -import de.neemann.digital.core.memory.Register; +import de.neemann.digital.core.memory.ProgramCounter; import de.neemann.digital.core.stats.Statistics; import de.neemann.digital.core.wiring.AsyncSeq; import de.neemann.digital.core.wiring.Clock; @@ -1777,9 +1777,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS private long address; private void getProgramROMAddress(Model model) { - List roms = model.findNode(Register.class, Register::isProgramCounter); - if (roms.size() == 1) - address = roms.get(0).getValue(); + List programCounters = model.findNode(n -> n instanceof ProgramCounter && ((ProgramCounter) n).isProgramCounter()); + if (programCounters.size() == 1) + address = ((ProgramCounter) programCounters.get(0)).getProgramCounter(); else address = -1; }