From a68c2984a0c724854fceacd5a9fb93cc742e0eeb Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 1 Apr 2016 14:11:38 +0200 Subject: [PATCH] added a simple terminal --- src/main/dig/processor/Processor.dig | 249 +++++++++++++++--- src/main/dig/processor/Terminal.dig | 151 +++++++++++ .../digital/core/element/AttributeKey.java | 2 + .../digital/draw/library/ElementLibrary.java | 2 + .../java/de/neemann/digital/gui/Main.java | 1 + .../gui/components/terminal/Terminal.java | 59 +++++ .../components/terminal/TerminalFrame.java | 43 +++ src/main/resources/lang/lang_de.properties | 3 + src/main/resources/lang/lang_en.properties | 2 + 9 files changed, 481 insertions(+), 31 deletions(-) create mode 100644 src/main/dig/processor/Terminal.dig create mode 100644 src/main/java/de/neemann/digital/gui/components/terminal/Terminal.java create mode 100644 src/main/java/de/neemann/digital/gui/components/terminal/TerminalFrame.java diff --git a/src/main/dig/processor/Processor.dig b/src/main/dig/processor/Processor.dig index 821b63e13..5dadf0afe 100644 --- a/src/main/dig/processor/Processor.dig +++ b/src/main/dig/processor/Processor.dig @@ -167,27 +167,172 @@ Data - 13 - 5137 + 158 5120 - 6145 - 15888 - 29521 - 15375 - 26107 - 8193 - 16400 - 29521 + 21328 + 21488 + 5130 + 21312 + 21472 + 32800 + 4608 + 21040 + 21104 + 21152 + 21200 + 21264 + 21424 + 32805 + 4608 + 21168 + 21280 + 21440 + 32865 + 4608 + 21216 + 32868 + 4608 + 21248 + 32869 + 4608 + 21024 + 21392 + 32870 + 4608 + 21136 + 32871 + 4608 + 21344 + 32872 + 4608 + 21008 + 32873 + 4608 + 21360 + 32877 + 4608 + 21088 + 32878 + 4608 + 21232 + 32879 + 4608 + 21120 + 32883 + 4608 + 21056 + 21408 + 32884 + 4608 + 20992 + 32885 + 4608 + 21072 + 32886 + 4608 + 21376 + 32888 + 4608 + 21184 + 21296 + 21456 + 5125 + 8417 + 19680 + 5124 + 8417 + 19680 + 5120 + 8417 + 19680 + 8417 + 32850 + 4848 + 19695 + 28175 + 6371 + 5129 + 8417 + 19680 + 5382 + 8417 + 19680 + 8417 + 32862 + 4848 + 19695 + 28163 + 6370 + 31744 + 28643 + 8417 + 19693 + 734 + 589 + 6210 + 20020 + 19971 15360 - 26107 - 28661 + 24070 + 32805 + 14848 + 24073 + 29680 + 6193 + 28663 + 749 + 20190 + 6369 + 20222 + 6369 + 27151 + 6193 + 19971 + 32888 + 14848 + 25605 + 6209 + 19972 + 32900 + 26864 + 28654 + 32805 + 4688 + 29685 + 28649 + 18432 + 18944 + 32915 + 26656 + 18944 + 32915 + 26656 + 18432 + 18944 + 32915 + 26656 + 18944 + 32915 + 26656 + 27151 + 528 + 10271 + 15386 + 25091 + 32816 + 5648 + 28162 + 32823 + 5648 + 29681 + 27138 16 lastDataFile - /home/hneemann/Dokumente/DHBW/Technische_Informatik_II/Systemnahes_Programmieren/java/assembler3/src/main/asm/lightChase.hex + /home/hneemann/Dokumente/DHBW/Technische_Informatik_II/Systemnahes_Programmieren/java/assembler3/src/main/asm/printf.hex @@ -372,6 +517,12 @@ 0 + + Terminal.dig + + + 0 + @@ -406,10 +557,6 @@ - - - - @@ -434,10 +581,18 @@ + + + + + + + + @@ -446,6 +601,14 @@ + + + + + + + + @@ -454,10 +617,6 @@ - - - - @@ -494,6 +653,14 @@ + + + + + + + + @@ -502,10 +669,6 @@ - - - - @@ -566,6 +729,10 @@ + + + + @@ -587,8 +754,8 @@ - - + + @@ -602,6 +769,10 @@ + + + + @@ -710,10 +881,6 @@ - - - - @@ -762,6 +929,10 @@ + + + + @@ -828,6 +999,10 @@ + + + + @@ -850,6 +1025,10 @@ + + + + @@ -886,6 +1065,10 @@ + + + + @@ -974,6 +1157,10 @@ + + + + diff --git a/src/main/dig/processor/Terminal.dig b/src/main/dig/processor/Terminal.dig new file mode 100644 index 000000000..03bcdd16b --- /dev/null +++ b/src/main/dig/processor/Terminal.dig @@ -0,0 +1,151 @@ + + + + + In + + + Label + A + + + Bits + 16 + + + + 0 + + + In + + + Label + D + + + Bits + 16 + + + + 0 + + + Comparator + + + Bits + 16 + + + + 0 + + + Const + + + Value + 31 + + + Bits + 16 + + + + 0 + + + Terminal + + + Label + Terminal + + + + 0 + + + In + + + Label + C + + + + 0 + + + And + + + Inputs + 3 + + + + 0 + + + In + + + Label + W + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/de/neemann/digital/core/element/AttributeKey.java b/src/main/java/de/neemann/digital/core/element/AttributeKey.java index 54f12760b..4b68ecb9f 100644 --- a/src/main/java/de/neemann/digital/core/element/AttributeKey.java +++ b/src/main/java/de/neemann/digital/core/element/AttributeKey.java @@ -24,6 +24,8 @@ public class AttributeKey { public static final AttributeKey FlipSelPositon = new AttributeKey<>("flipSelPos", Lang.get("key_flipSelPos"), false); public static final AttributeKey Rotate = new AttributeKey<>("rotation", Lang.get("key_rotation"), new Rotation(0)); public static final AttributeKey Width = new AttributeKey<>("Width", Lang.get("key_width"), 3); + public static final AttributeKey TermWidth = new AttributeKey<>("termWidth", Lang.get("key_termWidth"), 50); + public static final AttributeKey TermHeight = new AttributeKey<>("termHeight", Lang.get("key_termHeight"), 25); public static final AttributeKey Cycles = new AttributeKey<>("Cycles", Lang.get("key_cycles"), 100000); diff --git a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java index c5049d900..d446b2b77 100644 --- a/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java +++ b/src/main/java/de/neemann/digital/draw/library/ElementLibrary.java @@ -15,6 +15,7 @@ import de.neemann.digital.core.io.In; import de.neemann.digital.core.io.Out; import de.neemann.digital.core.memory.*; import de.neemann.digital.core.wiring.*; +import de.neemann.digital.gui.components.terminal.Terminal; import de.neemann.digital.lang.Lang; import java.util.ArrayList; @@ -51,6 +52,7 @@ public class ElementLibrary implements Iterable add(Break.DESCRIPTION, menu); add(Out.SEVENDESCRIPTION, menu); add(Out.SEVENHEXDESCRIPTION, menu); + add(Terminal.DESCRIPTION, menu); menu = Lang.get("lib_mux"); add(Multiplexer.DESCRIPTION, menu); diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index d01b64f0a..f524837c8 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -361,6 +361,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave { private void createAndStartModel(boolean runClock, ModelEvent.Event updateEvent) { try { + circuitComponent.removeHighLighted(); circuitComponent.setModeAndReset(CircuitComponent.Mode.running); setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library), runClock); diff --git a/src/main/java/de/neemann/digital/gui/components/terminal/Terminal.java b/src/main/java/de/neemann/digital/gui/components/terminal/Terminal.java new file mode 100644 index 000000000..4a120422e --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/components/terminal/Terminal.java @@ -0,0 +1,59 @@ +package de.neemann.digital.gui.components.terminal; + +import de.neemann.digital.core.Node; +import de.neemann.digital.core.NodeException; +import de.neemann.digital.core.ObservableValue; +import de.neemann.digital.core.element.AttributeKey; +import de.neemann.digital.core.element.Element; +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.ElementTypeDescription; + +/** + * @author hneemann + */ +public class Terminal extends Node implements Element { + + public static final ElementTypeDescription DESCRIPTION + = new ElementTypeDescription(Terminal.class, "D", "C") + .addAttribute(AttributeKey.TermWidth) + .addAttribute(AttributeKey.TermHeight) + .addAttribute(AttributeKey.Rotate) + .addAttribute(AttributeKey.Label); + + private final ElementAttributes attr; + private ObservableValue data; + private ObservableValue clock; + private TerminalFrame terminalFrame; + private boolean lastClock; + + public Terminal(ElementAttributes attributes) { + attr = attributes; + } + + @Override + public void setInputs(ObservableValue... inputs) throws NodeException { + data = inputs[0]; + clock = inputs[1].addObserver(this).checkBits(1, this); + } + + @Override + public ObservableValue[] getOutputs() { + return new ObservableValue[0]; + } + + @Override + public void readInputs() throws NodeException { + boolean clockVal = clock.getBool(); + if (!lastClock && clockVal) { + if (terminalFrame == null) + terminalFrame = new TerminalFrame(attr); + terminalFrame.addChar((char) data.getValue()); + } + lastClock = clockVal; + } + + @Override + public void writeOutputs() throws NodeException { + } + +} diff --git a/src/main/java/de/neemann/digital/gui/components/terminal/TerminalFrame.java b/src/main/java/de/neemann/digital/gui/components/terminal/TerminalFrame.java new file mode 100644 index 000000000..8828c7451 --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/components/terminal/TerminalFrame.java @@ -0,0 +1,43 @@ +package de.neemann.digital.gui.components.terminal; + +import de.neemann.digital.core.element.AttributeKey; +import de.neemann.digital.core.element.ElementAttributes; + +import javax.swing.*; +import java.awt.*; + + +/** + * @author hneemann + */ +public class TerminalFrame extends JFrame { + private final JTextArea textArea; + private final int width; + private int pos; + + public TerminalFrame(ElementAttributes attr) { + super(attr.get(AttributeKey.Label)); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + width = attr.get(AttributeKey.TermWidth); + textArea = new JTextArea(attr.get(AttributeKey.TermHeight), width); + textArea.setFont(new Font("monospaced", Font.PLAIN, 12)); + getContentPane().add(new JScrollPane(textArea)); + pack(); + setLocationRelativeTo(null); + setVisible(true); + } + + public void addChar(char value) { + if (value == 13 || value == 10) { + pos = 0; + textArea.append("\n"); + } else { + textArea.append("" + value); + pos++; + if (pos == width) { + pos = 0; + textArea.append("\n"); + } + } + } +} diff --git a/src/main/resources/lang/lang_de.properties b/src/main/resources/lang/lang_de.properties index 62e0ec7a4..310aea56f 100644 --- a/src/main/resources/lang/lang_de.properties +++ b/src/main/resources/lang/lang_de.properties @@ -29,6 +29,8 @@ key_flipSelPos=Tausche Position des Selectors key_rotation=Rotation key_width=Breite key_cycles=Timeout Zyklen +key_termWidth=Zeichen pro Zeile +key_termHeight=Zeilen rot_0=0\u00B0 rot_90=90\u00B0 @@ -132,6 +134,7 @@ menu_fast=Schneller Lauf menu_fast_tt=F\u00FChrt das Modell aus, bis ein Stopsignal \u00FCber ein BRK-Element detektiert wird. menu_export=Export menu_exportSVG=Export SVG +menu_exportSVGLaTex=Export SVG+LaTeX menu_delete=L\u00F6schen menu_delete_tt=L\u00F6scht ausgew\u00E4hlte Elemente diff --git a/src/main/resources/lang/lang_en.properties b/src/main/resources/lang/lang_en.properties index 348f36a7b..4b19c757e 100644 --- a/src/main/resources/lang/lang_en.properties +++ b/src/main/resources/lang/lang_en.properties @@ -29,6 +29,8 @@ key_flipSelPos=Flip selector position key_rotation=Rotation key_width=Width key_cycles=Timeout cycles +key_termWidth=Characters per line +key_termHeight=Lines rot_0=0\u00B0 rot_90=90\u00B0