use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class AssemblyWindow method updateHighlightLine.
private void updateHighlightLine() {
String where;
if (combo.getSelectedItem() != null) {
selReg = entry.get(combo.getSelectedItem().toString());
Value val = curCircuitState.getInstanceState(selReg).getPortValue(Register.OUT);
if (val.isFullyDefined()) {
where = val.toHexString().replaceAll("^0*", "");
if (where.isEmpty()) {
where = "0";
}
Pattern pattern = Pattern.compile("^[ ]+" + where + ":", Pattern.MULTILINE + Pattern.CASE_INSENSITIVE);
Matcher m = pattern.matcher(document.getText().replaceAll("\r", ""));
if (m.find()) {
document.setCaretPosition(m.start());
status.setText("");
try {
// bug fix, highligh active line
document.getHighlighter().removeAllHighlights();
DefaultHighlighter.DefaultHighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
document.getHighlighter().addHighlight(m.start(), m.end(), highlightPainter);
} catch (BadLocationException ex) {
ex.printStackTrace();
}
} else {
status.setText("Line (" + where + ") not found!");
}
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class ChronoModelEventHandler method entryAdded.
@Override
public void entryAdded(ModelEvent event, Value[] values) {
if (chronoFrame.isRealTimeMode() && (sysclkPos >= 0)) {
try {
// update gui only on sysclk change
if (!values[sysclkPos].toString().equals(lastSysclk)) {
lastSysclk = values[sysclkPos].toString();
int pos = 0;
for (Value v : values) {
chronoData.appendValueToSignal(signalNamesKeepOrder[pos++], v.toString());
}
chronoFrame.getChronoData().updateRealTimeExpandedBus();
chronoFrame.repaintAll(false);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Analyze method computeTable.
//
// ComputeTable
//
/**
* Returns a truth table corresponding to the circuit.
*/
public static void computeTable(AnalyzerModel model, Project proj, Circuit circuit, Map<Instance, String> pinLabels) {
ArrayList<Instance> inputPins = new ArrayList<Instance>();
ArrayList<String> inputNames = new ArrayList<String>();
ArrayList<Instance> outputPins = new ArrayList<Instance>();
ArrayList<String> outputNames = new ArrayList<String>();
for (Map.Entry<Instance, String> entry : pinLabels.entrySet()) {
Instance pin = entry.getKey();
if (Pin.FACTORY.isInputPin(pin)) {
inputPins.add(pin);
inputNames.add(entry.getValue());
} else {
outputPins.add(pin);
outputNames.add(entry.getValue());
}
}
int inputCount = inputPins.size();
int rowCount = 1 << inputCount;
Entry[][] columns = new Entry[outputPins.size()][rowCount];
for (int i = 0; i < rowCount; i++) {
CircuitState circuitState = new CircuitState(proj, circuit);
for (int j = 0; j < inputCount; j++) {
Instance pin = inputPins.get(j);
InstanceState pinState = circuitState.getInstanceState(pin);
boolean value = TruthTable.isInputSet(i, j, inputCount);
Pin.FACTORY.setValue(pinState, value ? Value.TRUE : Value.FALSE);
}
Propagator prop = circuitState.getPropagator();
prop.propagate();
if (prop.isOscillating()) {
for (int j = 0; j < columns.length; j++) {
columns[j][i] = Entry.OSCILLATE_ERROR;
}
} else {
for (int j = 0; j < columns.length; j++) {
Instance pin = outputPins.get(j);
InstanceState pinState = circuitState.getInstanceState(pin);
Entry out;
Value outValue = Pin.FACTORY.getValue(pinState).get(0);
if (outValue == Value.TRUE)
out = Entry.ONE;
else if (outValue == Value.FALSE)
out = Entry.ZERO;
else if (outValue == Value.ERROR)
out = Entry.BUS_ERROR;
else
out = Entry.DONT_CARE;
columns[j][i] = out;
}
}
}
model.setVariables(inputNames, outputNames);
for (int i = 0; i < columns.length; i++) {
model.getTruthTable().setOutputColumn(i, columns[i]);
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class CounterData method updateClock.
/**
* Updates the last clock observed, returning true if triggered.
*/
public boolean updateClock(Value value) {
Value old = lastClock;
lastClock = value;
return old == Value.FALSE && value == Value.TRUE;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class CounterPoker method keyTyped.
/**
* Processes a key by just adding it onto the end of the current value.
*/
@Override
public void keyTyped(InstanceState state, KeyEvent e) {
// convert it to a hex digit; if it isn't a hex digit, abort.
int val = Character.digit(e.getKeyChar(), 16);
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
if (val < 0 || (val & width.getMask()) != val)
return;
// compute the next value
CounterData cur = CounterData.get(state, width);
int newVal = (cur.getValue().toIntValue() * 16 + val) & width.getMask();
Value newValue = Value.createKnown(width, newVal);
cur.setValue(newValue);
state.fireInvalidated();
// You might be tempted to propagate the value immediately here, using
// state.setPort. However, the circuit may currently be propagating in
// another thread, and invoking setPort directly could interfere with
// that. Using fireInvalidated notifies the propagation thread to
// invoke propagate on the counter at its next opportunity.
}
Aggregations