mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 06:49:36 -04:00
added a delay
This commit is contained in:
parent
1b0d26cbf4
commit
c95ec22fef
57
src/main/java/de/neemann/digital/core/wiring/Delay.java
Normal file
57
src/main/java/de/neemann/digital/core/wiring/Delay.java
Normal file
@ -0,0 +1,57 @@
|
||||
package de.neemann.digital.core.wiring;
|
||||
|
||||
import de.neemann.digital.core.BitsException;
|
||||
import de.neemann.digital.core.Node;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.part.AttributeKey;
|
||||
import de.neemann.digital.core.part.Part;
|
||||
import de.neemann.digital.core.part.PartAttributes;
|
||||
import de.neemann.digital.core.part.PartTypeDescription;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class Delay extends Node implements Part {
|
||||
|
||||
public static final PartTypeDescription DESCRIPTION = new PartTypeDescription(Delay.class, "in");
|
||||
|
||||
private final ObservableValue output;
|
||||
private final int bits;
|
||||
private ObservableValue input;
|
||||
private long value;
|
||||
|
||||
public Delay(PartAttributes attributes) {
|
||||
bits = attributes.get(AttributeKey.Bits);
|
||||
output = new ObservableValue("out", bits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readInputs() throws NodeException {
|
||||
value = input.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeOutputs() throws NodeException {
|
||||
output.setValue(value);
|
||||
}
|
||||
|
||||
public ObservableValue getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||
input = inputs[0];
|
||||
input.addListener(this);
|
||||
|
||||
if (input.getBits() != bits)
|
||||
throw new BitsException("wrongBitCountInDelay", input, output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValue[] getOutputs() {
|
||||
return new ObservableValue[]{output};
|
||||
}
|
||||
|
||||
}
|
@ -41,7 +41,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
|
||||
public Main() {
|
||||
super("Digital");
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
|
||||
|
||||
Circuit cr = new Circuit();
|
||||
@ -230,6 +230,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
try (FileWriter out = new FileWriter(filename)) {
|
||||
xStream.marshal(circuitComponent.getCircuit(), new PrettyPrintWriter(out));
|
||||
setFilename(filename);
|
||||
circuitComponent.getCircuit().saved();
|
||||
} catch (IOException e) {
|
||||
new ErrorMessage("error writing a file").addCause(e).show();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import de.neemann.digital.core.io.In;
|
||||
import de.neemann.digital.core.io.LED;
|
||||
import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.part.PartTypeDescription;
|
||||
import de.neemann.digital.core.wiring.Delay;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -34,6 +35,7 @@ public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
||||
add(XOr.DESCRIPTION, "Logic");
|
||||
add(XNOr.DESCRIPTION, "Logic");
|
||||
add(Not.DESCRIPTION, "Logic");
|
||||
add(Delay.DESCRIPTION, "Logic");
|
||||
|
||||
add(In.DESCRIPTION, "IO");
|
||||
add(Out.DESCRIPTION, "IO");
|
||||
|
@ -116,4 +116,8 @@ public class Circuit implements Drawable {
|
||||
public boolean isModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void saved() {
|
||||
modified = false;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class OutputShape implements Shape {
|
||||
Vector center = new Vector(2 + SIZE, 0);
|
||||
graphic.drawCircle(center.sub(RAD), center.add(RAD), style);
|
||||
graphic.drawCircle(center.sub(RADL), center.add(RADL), Style.NORMAL);
|
||||
Vector textPos = new Vector(SIZE * 3, 0);
|
||||
Vector textPos = new Vector(SIZE * 2 + 3, 0);
|
||||
graphic.drawText(textPos, textPos.add(1, 0), label, Orientation.LEFTCENTER, Style.NORMAL);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.part.AttributeKey;
|
||||
import de.neemann.digital.core.part.PartAttributes;
|
||||
import de.neemann.digital.core.part.PartTypeDescription;
|
||||
import de.neemann.digital.core.wiring.Delay;
|
||||
import de.neemann.digital.gui.draw.library.PartLibrary;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -30,6 +31,7 @@ public final class ShapeFactory {
|
||||
map.put(NAnd.DESCRIPTION.getName(), new CreatorSimple("&", NAnd.DESCRIPTION, true));
|
||||
map.put(NOr.DESCRIPTION.getName(), new CreatorSimple("\u22651", NOr.DESCRIPTION, true));
|
||||
map.put(Not.DESCRIPTION.getName(), new CreatorSimple("", Not.DESCRIPTION, true));
|
||||
map.put(Delay.DESCRIPTION.getName(), new CreatorSimple("", Delay.DESCRIPTION, false));
|
||||
|
||||
map.put(XOr.DESCRIPTION.getName(), new CreatorSimple("=1", XOr.DESCRIPTION, false));
|
||||
map.put(XNOr.DESCRIPTION.getName(), new CreatorSimple("=1", XNOr.DESCRIPTION, true));
|
||||
|
Loading…
x
Reference in New Issue
Block a user