use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TtyInterface method runSimulation.
private static int runSimulation(CircuitState circState, ArrayList<Instance> outputPins, Instance haltPin, int format) {
boolean showTable = (format & FORMAT_TABLE) != 0;
boolean showSpeed = (format & FORMAT_SPEED) != 0;
boolean showTty = (format & FORMAT_TTY) != 0;
boolean showHalt = (format & FORMAT_HALT) != 0;
ArrayList<InstanceState> keyboardStates = null;
StdinThread stdinThread = null;
if (showTty) {
keyboardStates = new ArrayList<InstanceState>();
boolean ttyFound = prepareForTty(circState, keyboardStates);
if (!ttyFound) {
logger.error("{}", Strings.get("ttyNoTtyError"));
System.exit(-1);
}
if (keyboardStates.isEmpty()) {
keyboardStates = null;
} else {
stdinThread = new StdinThread();
stdinThread.start();
}
}
int retCode;
long tickCount = 0;
long start = System.currentTimeMillis();
boolean halted = false;
ArrayList<Value> prevOutputs = null;
Propagator prop = circState.getPropagator();
while (true) {
ArrayList<Value> curOutputs = new ArrayList<Value>();
for (Instance pin : outputPins) {
InstanceState pinState = circState.getInstanceState(pin);
Value val = Pin.FACTORY.getValue(pinState);
if (pin == haltPin) {
halted |= val.equals(Value.TRUE);
} else if (showTable) {
curOutputs.add(val);
}
}
if (showTable) {
displayTableRow(prevOutputs, curOutputs);
}
if (halted) {
// normal exit
retCode = 0;
break;
}
if (prop.isOscillating()) {
// abnormal exit
retCode = 1;
break;
}
if (keyboardStates != null) {
char[] buffer = stdinThread.getBuffer();
if (buffer != null) {
for (InstanceState keyState : keyboardStates) {
Keyboard.addToBuffer(keyState, buffer);
}
}
}
prevOutputs = curOutputs;
tickCount++;
prop.tick();
prop.propagate();
}
long elapse = System.currentTimeMillis() - start;
if (showTty)
ensureLineTerminated();
if (showHalt || retCode != 0) {
if (retCode == 0) {
logger.error("{}", Strings.get("ttyHaltReasonPin"));
} else if (retCode == 1) {
logger.error("{}", Strings.get("ttyHaltReasonOscillation"));
}
}
if (showSpeed) {
displaySpeed(tickCount, elapse);
}
return retCode;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TestPanel method getRowData.
public void getRowData(int firstRow, int numRows, ValueTable.Cell[][] rowData) {
Model model = getModel();
TestException[] results = model.getResults();
int numPass = model.getPass();
int numFail = model.getFail();
TestVector vec = model.getVector();
int columns = vec.columnName.length;
String[] msg = new String[columns];
Value[] altdata = new Value[columns];
String passMsg = Strings.get("passStatus");
String failMsg = Strings.get("failStatus");
for (int i = firstRow; i < firstRow + numRows; i++) {
int row = model.sortedIndex(i);
Value[] data = vec.data.get(row);
String rowmsg = null;
String status = null;
boolean failed = false;
if (row < numPass + numFail) {
TestException err = results[row];
if (err != null && err instanceof FailException) {
failed = true;
for (FailException e = (FailException) err; e != null; e = e.getMore()) {
int col = e.getColumn();
msg[col] = StringUtil.format(Strings.get("expectedValueMessage"), e.getExpected().toDisplayString(getColumnValueRadix(col + 1)));
altdata[col] = e.getComputed();
}
} else if (err != null) {
failed = true;
rowmsg = err.getMessage();
}
status = failed ? failMsg : passMsg;
}
rowData[i - firstRow][0] = new ValueTable.Cell(status, rowmsg != null ? failColor : null, null, rowmsg);
for (int col = 0; col < columns; col++) {
rowData[i - firstRow][col + 1] = new ValueTable.Cell(altdata[col] != null ? altdata[col] : data[col], msg[col] != null ? failColor : null, null, msg[col]);
msg[col] = null;
altdata[col] = null;
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class SubcircuitFactory method propagate.
@Override
public void propagate(InstanceState superState) {
CircuitState subState = getSubstate(superState);
CircuitAttributes attrs = (CircuitAttributes) superState.getAttributeSet();
Instance[] pins = attrs.getPinInstances();
for (int i = 0; i < pins.length; i++) {
Instance pin = pins[i];
InstanceState pinState = subState.getInstanceState(pin);
if (Pin.FACTORY.isInputPin(pin)) {
Value newVal = superState.getPortValue(i);
Value oldVal = Pin.FACTORY.getValue(pinState);
if (!newVal.equals(oldVal)) {
Pin.FACTORY.setValue(pinState, newVal);
Pin.FACTORY.propagate(pinState);
}
} else {
// it is output-only
Value val = pinState.getPortValue(0);
superState.setPort(i, val, 1);
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class CircuitWires method propagate.
//
// utility methods
//
void propagate(CircuitState circState, Set<Location> points) {
BundleMap map = getBundleMap();
// affected
CopyOnWriteArraySet<WireThread> dirtyThreads = new CopyOnWriteArraySet<WireThread>();
// threads
// get state, or create a new one if current state is outdated
State s = circState.getWireData();
if (s == null || s.bundleMap != map) {
// if it is outdated, we need to compute for all threads
s = new State(map);
for (WireBundle b : map.getBundles()) {
WireThread[] th = b.threads;
if (b.isValid() && th != null) {
for (WireThread t : th) {
dirtyThreads.add(t);
}
}
}
circState.setWireData(s);
}
// determine affected threads, and set values for unwired points
for (Location p : points) {
WireBundle pb = map.getBundleAt(p);
if (pb == null) {
// point is not wired
circState.setValueByWire(p, circState.getComponentOutputAt(p));
} else {
WireThread[] th = pb.threads;
if (!pb.isValid() || th == null) {
// immediately propagate NILs across invalid bundles
CopyOnWriteArraySet<Location> pbPoints = pb.points;
if (pbPoints == null) {
circState.setValueByWire(p, Value.NIL);
} else {
for (Location loc2 : pbPoints) {
circState.setValueByWire(loc2, Value.NIL);
}
}
} else {
for (WireThread t : th) {
dirtyThreads.add(t);
}
}
}
}
if (dirtyThreads.isEmpty())
return;
// determine values of affected threads
HashSet<ThreadBundle> bundles = new HashSet<ThreadBundle>();
for (WireThread t : dirtyThreads) {
Value v = getThreadValue(circState, t);
s.thr_values.put(t, v);
bundles.addAll(t.getBundles());
}
// now propagate values through circuit
for (ThreadBundle tb : bundles) {
WireBundle b = tb.b;
Value bv = null;
if (!b.isValid() || b.threads == null) {
// do nothing
;
} else if (b.threads.length == 1) {
bv = s.thr_values.get(b.threads[0]);
} else {
Value[] tvs = new Value[b.threads.length];
boolean tvs_valid = true;
for (int i = 0; i < tvs.length; i++) {
Value tv = s.thr_values.get(b.threads[i]);
if (tv == null) {
tvs_valid = false;
break;
}
tvs[i] = tv;
}
if (tvs_valid)
bv = Value.create(tvs);
}
if (bv != null) {
for (Location p : b.points) {
circState.setValueByWire(p, bv);
}
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Propagator method checkComponentEnds.
//
// private methods
//
void checkComponentEnds(CircuitState state, Component comp) {
for (EndData end : comp.getEnds()) {
Location loc = end.getLocation();
SetData oldHead = state.causes.get(loc);
Value oldVal = computeValue(oldHead);
SetData newHead = removeCause(state, oldHead, loc, comp);
Value newVal = computeValue(newHead);
Value wireVal = state.getValueByWire(loc);
if (!newVal.equals(oldVal) || wireVal != null) {
state.markPointAsDirty(loc);
}
if (wireVal != null)
state.setValueByWire(loc, Value.NIL);
}
}
Aggregations