Search in sources :

Example 41 with Value

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!");
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Value(com.cburch.logisim.data.Value) DefaultHighlighter(javax.swing.text.DefaultHighlighter) BadLocationException(javax.swing.text.BadLocationException)

Example 42 with Value

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();
        }
    }
}
Also used : Value(com.cburch.logisim.data.Value)

Example 43 with Value

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]);
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Entry(com.cburch.logisim.analyze.model.Entry) InstanceState(com.cburch.logisim.instance.InstanceState) Value(com.cburch.logisim.data.Value) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 44 with Value

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;
}
Also used : Value(com.cburch.logisim.data.Value)

Example 45 with Value

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.
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Aggregations

Value (com.cburch.logisim.data.Value)89 BitWidth (com.cburch.logisim.data.BitWidth)30 Graphics (java.awt.Graphics)15 Location (com.cburch.logisim.data.Location)9 Color (java.awt.Color)8 Bounds (com.cburch.logisim.data.Bounds)7 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)7 AttributeSet (com.cburch.logisim.data.AttributeSet)6 InstanceState (com.cburch.logisim.instance.InstanceState)6 Direction (com.cburch.logisim.data.Direction)3 Instance (com.cburch.logisim.instance.Instance)3 Port (com.cburch.logisim.instance.Port)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 FailException (com.cburch.logisim.data.FailException)2 TestException (com.cburch.logisim.data.TestException)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2