mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
added micro stepping
This commit is contained in:
parent
9200771046
commit
5f3b608fff
@ -41,37 +41,41 @@ public class Model {
|
|||||||
|
|
||||||
public void doStep(boolean noise) throws NodeException {
|
public void doStep(boolean noise) throws NodeException {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (!nodesToUpdateNext.isEmpty()) {
|
while (!doMicroStep(noise)) {
|
||||||
version++;
|
if (listener != null)
|
||||||
// swap lists
|
listener.needsUpdate();
|
||||||
ArrayList<Node> nl = nodesToUpdateNext;
|
|
||||||
nodesToUpdateNext = nodesToUpdateAct;
|
|
||||||
nodesToUpdateAct = nl;
|
|
||||||
|
|
||||||
nodesToUpdateNext.clear();
|
|
||||||
|
|
||||||
if (noise) {
|
|
||||||
Collections.shuffle(nodesToUpdateAct);
|
|
||||||
for (Node n : nodesToUpdateAct) {
|
|
||||||
n.readInputs();
|
|
||||||
n.writeOutputs();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (Node n : nodesToUpdateAct) {
|
|
||||||
n.readInputs();
|
|
||||||
}
|
|
||||||
for (Node n : nodesToUpdateAct) {
|
|
||||||
n.writeOutputs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (counter++ > maxCounter) {
|
if (counter++ > maxCounter) {
|
||||||
throw new NodeException("seemsToOscillate");
|
throw new NodeException("seemsToOscillate");
|
||||||
}
|
}
|
||||||
if (listener != null)
|
|
||||||
listener.needsUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean doMicroStep(boolean noise) throws NodeException {
|
||||||
|
version++;
|
||||||
|
// swap lists
|
||||||
|
ArrayList<Node> nl = nodesToUpdateNext;
|
||||||
|
nodesToUpdateNext = nodesToUpdateAct;
|
||||||
|
nodesToUpdateAct = nl;
|
||||||
|
|
||||||
|
nodesToUpdateNext.clear();
|
||||||
|
|
||||||
|
if (noise) {
|
||||||
|
Collections.shuffle(nodesToUpdateAct);
|
||||||
|
for (Node n : nodesToUpdateAct) {
|
||||||
|
n.readInputs();
|
||||||
|
n.writeOutputs();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (Node n : nodesToUpdateAct) {
|
||||||
|
n.readInputs();
|
||||||
|
}
|
||||||
|
for (Node n : nodesToUpdateAct) {
|
||||||
|
n.writeOutputs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodesToUpdateNext.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public void init() throws NodeException {
|
public void init() throws NodeException {
|
||||||
init(false);
|
init(false);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package de.neemann.digital.gui;
|
|||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||||
import com.thoughtworks.xstream.io.xml.StaxDriver;
|
import com.thoughtworks.xstream.io.xml.StaxDriver;
|
||||||
|
import de.neemann.digital.core.Listener;
|
||||||
import de.neemann.digital.core.Model;
|
import de.neemann.digital.core.Model;
|
||||||
import de.neemann.digital.core.PartDescription;
|
import de.neemann.digital.core.PartDescription;
|
||||||
import de.neemann.digital.core.basic.*;
|
import de.neemann.digital.core.basic.*;
|
||||||
@ -121,14 +122,29 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
JMenu run = new JMenu("Run");
|
JMenu run = new JMenu("Run");
|
||||||
bar.add(run);
|
bar.add(run);
|
||||||
|
|
||||||
|
JCheckBox microStep = new JCheckBox("micro");
|
||||||
|
|
||||||
ToolTipAction runModel = new ToolTipAction("Run") {
|
ToolTipAction runModel = new ToolTipAction("Run") {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
try {
|
||||||
ModelDescription m = new ModelDescription(circuitComponent.getCircuit());
|
|
||||||
Model model = m.create(circuitComponent);
|
|
||||||
model.init(true);
|
|
||||||
circuitComponent.setMode(CircuitComponent.Mode.running);
|
circuitComponent.setMode(CircuitComponent.Mode.running);
|
||||||
|
ModelDescription m = new ModelDescription(circuitComponent.getCircuit());
|
||||||
|
Model model = m.createModel(circuitComponent);
|
||||||
|
if (microStep.isSelected()) {
|
||||||
|
model.setListener(new Listener() {
|
||||||
|
@Override
|
||||||
|
public void needsUpdate() {
|
||||||
|
circuitComponent.paintImmediately(circuitComponent.getVisibleRect());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
model.init(true);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
new ErrorMessage("error creating model").addCause(e1).show(Main.this);
|
new ErrorMessage("error creating model").addCause(e1).show(Main.this);
|
||||||
}
|
}
|
||||||
@ -142,6 +158,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
toolBar.add(partsMode.createJButton());
|
toolBar.add(partsMode.createJButton());
|
||||||
toolBar.add(wireMode.createJButton());
|
toolBar.add(wireMode.createJButton());
|
||||||
toolBar.add(selectionMode.createJButton());
|
toolBar.add(selectionMode.createJButton());
|
||||||
|
toolBar.add(runModel.createJButton());
|
||||||
|
toolBar.add(microStep);
|
||||||
|
|
||||||
toolBar.addSeparator();
|
toolBar.addSeparator();
|
||||||
insertHistory = new InsertHistory(toolBar);
|
insertHistory = new InsertHistory(toolBar);
|
||||||
|
@ -75,6 +75,7 @@ public class CircuitComponent extends JComponent implements Listener {
|
|||||||
addMouseMotionListener(listener);
|
addMouseMotionListener(listener);
|
||||||
addMouseListener(listener);
|
addMouseListener(listener);
|
||||||
requestFocusInWindow();
|
requestFocusInWindow();
|
||||||
|
circuit.clearState();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public class ModelDescription {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Model create(Listener listener) throws PinException, NodeException {
|
public Model createModel(Listener listener) throws PinException, NodeException {
|
||||||
for (Net n : netList)
|
for (Net n : netList)
|
||||||
n.interconnect();
|
n.interconnect();
|
||||||
|
|
||||||
|
@ -105,4 +105,11 @@ public class Circuit implements Drawable {
|
|||||||
dots = WireConsistencyChecker.createDots(wires);
|
dots = WireConsistencyChecker.createDots(wires);
|
||||||
return dots;
|
return dots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearState() {
|
||||||
|
for (VisualPart vp : visualParts)
|
||||||
|
vp.setState(null, null, null);
|
||||||
|
for (Wire w : wires)
|
||||||
|
w.setValue(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,10 @@ public class VisualPart implements Drawable, Moveable {
|
|||||||
*/
|
*/
|
||||||
public void setState(State state, Listener listener, Model model) {
|
public void setState(State state, Listener listener, Model model) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
interactor = partDescription.getShape().applyStateMonitor(state, listener, model);
|
if (state == null)
|
||||||
|
interactor = null;
|
||||||
|
else
|
||||||
|
interactor = partDescription.getShape().applyStateMonitor(state, listener, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clicked(CircuitComponent cc, Vector pos) {
|
public void clicked(CircuitComponent cc, Vector pos) {
|
||||||
|
@ -76,21 +76,6 @@ public class GenericShape implements Shape {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Interactor applyStateMonitor(State state, Listener listener, Model model) {
|
public Interactor applyStateMonitor(State state, Listener listener, Model model) {
|
||||||
if (symmetric) {
|
|
||||||
state.getOutput(0).addListener(new Listener() {
|
|
||||||
public long lastValue = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void needsUpdate() {
|
|
||||||
long value = state.getInput(0).getValue();
|
|
||||||
if (lastValue != value) {
|
|
||||||
lastValue = value;
|
|
||||||
listener.needsUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +84,9 @@ public class GenericShape implements Shape {
|
|||||||
int max = Math.max(inputs, outputs);
|
int max = Math.max(inputs, outputs);
|
||||||
int height = (max - 1) * SIZE + SIZE2;
|
int height = (max - 1) * SIZE + SIZE2;
|
||||||
|
|
||||||
if (symmetric && state != null) {
|
// if (symmetric && state != null) {
|
||||||
graphic.drawText(new Vector(width * SIZE, 0), new Vector((width + 1) * SIZE, 0), Long.toString(state.getOutput(0).getValue()));
|
// graphic.drawText(new Vector(width * SIZE, 0), new Vector((width + 1) * SIZE, 0), Long.toString(state.getOutput(0).getValue()));
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (symmetric && ((inputs & 1) == 0)) height += SIZE;
|
if (symmetric && ((inputs & 1) == 0)) height += SIZE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user