Search in sources :

Example 81 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class BitSelector method propagate.

@Override
public void propagate(InstanceState state) {
    Value data = state.getPortValue(1);
    Value select = state.getPortValue(2);
    BitWidth groupBits = state.getAttributeValue(GROUP_ATTR);
    Value group;
    if (!select.isFullyDefined()) {
        group = Value.createUnknown(groupBits);
    } else {
        int shift = select.toIntValue() * groupBits.getWidth();
        if (shift >= data.getWidth()) {
            group = Value.createKnown(groupBits, 0);
        } else if (groupBits.getWidth() == 1) {
            group = data.get(shift);
        } else {
            Value[] bits = new Value[groupBits.getWidth()];
            for (int i = 0; i < bits.length; i++) {
                if (shift + i >= data.getWidth()) {
                    bits[i] = Value.FALSE;
                } else {
                    bits[i] = data.get(shift + i);
                }
            }
            group = Value.create(bits);
        }
    }
    state.setPort(0, group, Plexers.DELAY);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 82 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class Decoder method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth data = BitWidth.ONE;
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    // determine default output values
    // the default output
    Value others;
    if (threeState.booleanValue()) {
        others = Value.UNKNOWN;
    } else {
        others = Value.FALSE;
    }
    // determine selected output value
    // the special output
    int outIndex = -1;
    Value out = null;
    Value en = enable ? state.getPortValue(outputs + 1) : Value.TRUE;
    if (en == Value.FALSE) {
        Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
        Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
        others = Value.repeat(base, data.getWidth());
    } else if (en == Value.ERROR && state.isPortConnected(outputs + 1)) {
        others = Value.createError(data);
    } else {
        Value sel = state.getPortValue(outputs);
        if (sel.isFullyDefined()) {
            outIndex = sel.toIntValue();
            out = Value.TRUE;
        } else if (sel.isErrorValue()) {
            others = Value.createError(data);
        } else {
            others = Value.createUnknown(data);
        }
    }
    // now propagate them
    for (int i = 0; i < outputs; i++) {
        state.setPort(i, i == outIndex ? out : others, Plexers.DELAY);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 83 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class TtyState method setLastClock.

public Value setLastClock(Value newClock) {
    Value ret = lastClock;
    lastClock = newClock;
    return ret;
}
Also used : Value(com.cburch.logisim.data.Value)

Example 84 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class AbstractFlipFlop method propagate.

@Override
public void propagate(InstanceState state) {
    // boolean changed = false;
    StateData data = (StateData) state.getData();
    if (data == null) {
        // changed = true;
        data = new StateData();
        state.setData(data);
    }
    int n = getPorts().size() - STD_PORTS;
    Object triggerType = state.getAttributeValue(triggerAttribute);
    boolean triggered = data.updateClock(state.getPortValue(n), triggerType);
    if (state.getPortValue(n + 3) == Value.TRUE) {
        // clear requested
        // changed |= data.curValue != Value.FALSE;
        data.curValue = Value.FALSE;
    } else if (state.getPortValue(n + 4) == Value.TRUE) {
        // preset
        // requested
        // changed |= data.curValue != Value.TRUE;
        data.curValue = Value.TRUE;
    } else if (triggered) /* && state.getPortValue(n + 5) != Value.FALSE */
    {
        // Clock has triggered and flip-flop is enabled: Update the state
        Value[] inputs = new Value[n];
        for (int i = 0; i < n; i++) {
            inputs[i] = state.getPortValue(i);
        }
        Value newVal = computeValue(inputs, data.curValue);
        if (newVal == Value.TRUE || newVal == Value.FALSE) {
            // changed |= data.curValue != newVal;
            data.curValue = newVal;
        }
    }
    state.setPort(n + 1, data.curValue, Memory.DELAY);
    state.setPort(n + 2, data.curValue.not(), Memory.DELAY);
}
Also used : Value(com.cburch.logisim.data.Value)

Example 85 with Value

use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.

the class TclComponent method propagate.

/**
 * This creates a new TCL process executing the TCL content file.
 * Communication is done through a socket
 *
 * @param state
 */
@Override
public void propagate(InstanceState state) {
    /*
             * The ComponentData is the persistent thing through logisim usage. It
             * doesn't change when you move the component when InstanceComponent
             * does.
             */
    TclComponentData tclComponentData = TclComponentData.get(state);
    tclComponentData.getTclWrapper().start();
    /*
             * Here we may miss the first clock if the TCL process is not soon fast
             * enought You may change this behavior, but blocking here seemed bad to
             * me
             */
    if (tclComponentData.isConnected()) {
        /* Send port values to the TCL wrapper */
        for (Port p : state.getInstance().getPorts()) {
            int index = state.getPortIndex(p);
            Value val = state.getPortValue(index);
            String message = p.getType() + ":" + p.getToolTip() + ":" + val.toBinaryString() + ":" + index;
            tclComponentData.send(message);
        }
        /* 
                 * If it is a new tick, ask the console to force the sti in the
                 * console and set them in Logisim in return. If it is not a new
                 * tick, simply send the updated obs to the console.
                 */
        if (tclComponentData.isNewTick()) {
            tclComponentData.send("sync_force");
            getPortsFromServer(state, tclComponentData);
        } else {
            tclComponentData.send("sync_examine");
            String server_response;
            /* Ignore all messages until "sync" is recieved */
            while ((server_response = tclComponentData.receive()) != null && server_response.length() > 0 && !server_response.equals("sync")) ;
        }
    }
}
Also used : Port(com.cburch.logisim.instance.Port) 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