diff --git a/src/main/java/de/neemann/digital/core/Model.java b/src/main/java/de/neemann/digital/core/Model.java index 5e4fe09b7..a888b61c9 100644 --- a/src/main/java/de/neemann/digital/core/Model.java +++ b/src/main/java/de/neemann/digital/core/Model.java @@ -432,15 +432,6 @@ public class Model implements Iterable { return n; } - - public void addProgRom(ROM rom) { - progRoms.add(rom); - } - - public ArrayList getProgRoms() { - return progRoms; - } - /** * fires a model changed event to all listeners */ @@ -463,13 +454,41 @@ public class Model implements Iterable { * @return the list, not null, but maybe empty */ public List findNode(Class nodeClass) { + return findNode(nodeClass, n -> true); + } + + /** + * Returns all nodes of the given class. + * A filter cann be used to narrow down the amount of nodes found. + * + * @param nodeClass the class + * @param filter filter to filter the nodes + * @param the node type + * @return the list, not null, but maybe empty + */ + public List findNode(Class nodeClass, NodeFilter filter) { ArrayList found = new ArrayList<>(); for (Node n : nodes) - if (n.getClass() == nodeClass) + if (n.getClass() == nodeClass && filter.accept((NODE) n)) found.add((NODE) n); return found; } + /** + * A filter for nodes + * + * @param + */ + public interface NodeFilter { + /** + * Accepts the node + * + * @param n the node + * @return true if accepted + */ + boolean accept(NODE n); + } + @Override public Iterator iterator() { return nodes.iterator(); diff --git a/src/main/java/de/neemann/digital/core/memory/ROM.java b/src/main/java/de/neemann/digital/core/memory/ROM.java index 7c14b2130..5a46d6553 100644 --- a/src/main/java/de/neemann/digital/core/memory/ROM.java +++ b/src/main/java/de/neemann/digital/core/memory/ROM.java @@ -101,9 +101,6 @@ public class ROM extends Node implements Element { @Override public void init(Model model) throws NodeException { - if (isProgramMemory) { - model.addProgRom(this); - } if (autoLoad) { try { data = new DataField(hexFile); diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index e1e08b1bc..8af6d2adc 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -986,7 +986,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E private long addr; private void getProgRomAddr(Model model) { - ArrayList roms = model.getProgRoms(); + List roms = model.findNode(ROM.class, ROM::isProgramMemory); if (roms.size() == 1) addr = roms.get(0).getRomAddress(); else @@ -1001,6 +1001,29 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E } } + private void setDebug(boolean debug) throws RemoteException { + settings.set(Keys.SHOW_DATA_TABLE, debug); + } + + @Override + public void start(File romHex) throws RemoteException { + setDebug(false); + SwingUtilities.invokeLater(() -> { + windowPosManager.closeAll(); + runModelState.enter(true, new RomLoader(romHex)); + circuitComponent.hasChanged(); + }); + } + + @Override + public void debug(File romHex) throws RemoteException { + setDebug(true); + SwingUtilities.invokeLater(() -> { + runModelState.enter(false, new RomLoader(romHex)); + circuitComponent.hasChanged(); + }); + } + @Override public String doSingleStep() throws RemoteException { if (model != null && !realtimeClockRunning) { @@ -1047,29 +1070,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E } } - private void setDebug(boolean debug) throws RemoteException { - settings.set(Keys.SHOW_DATA_TABLE, debug); - } - - @Override - public void debug(File romHex) throws RemoteException { - setDebug(true); - SwingUtilities.invokeLater(() -> { - runModelState.enter(false, new RomLoader(romHex)); - circuitComponent.hasChanged(); - }); - } - - @Override - public void start(File romHex) throws RemoteException { - setDebug(false); - SwingUtilities.invokeLater(() -> { - windowPosManager.closeAll(); - runModelState.enter(true, new RomLoader(romHex)); - circuitComponent.hasChanged(); - }); - } - @Override public void stop() { SwingUtilities.invokeLater(() -> { diff --git a/src/main/java/de/neemann/digital/gui/RomLoader.java b/src/main/java/de/neemann/digital/gui/RomLoader.java index 20db205ce..597540a90 100644 --- a/src/main/java/de/neemann/digital/gui/RomLoader.java +++ b/src/main/java/de/neemann/digital/gui/RomLoader.java @@ -8,7 +8,7 @@ import de.neemann.digital.lang.Lang; import java.io.File; import java.io.IOException; -import java.util.ArrayList; +import java.util.List; /** * A Modifier that loads a given rom file to the program memory of the model. @@ -28,7 +28,7 @@ public class RomLoader implements ModelModifier { @Override public void preInit(Model model) throws NodeException { - ArrayList roms = model.getProgRoms(); + List roms = model.findNode(ROM.class, ROM::isProgramMemory); if (roms.isEmpty()) throw new NodeException(Lang.get("msg_noRomFound")); if (roms.size() > 1)