Search in sources :

Example 86 with Value

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

the class TclComponentData method isNewTick.

public boolean isNewTick() {
    boolean newTick = false;
    boolean found = false;
    for (Port p : instanceState.getInstance().getPorts()) {
        if (p.getToolTip().equals("sysclk_i")) {
            Value val = instanceState.getPortValue(instanceState.getPortIndex(p));
            newTick = (val != prevClockValue);
            if (newTick) {
                prevClockValue = val;
            }
            found = true;
            break;
        }
    }
    if (!found) {
        throw new UnsupportedOperationException("Could not find the 'sysclock' in the TCL component");
    }
    return newTick;
}
Also used : Port(com.cburch.logisim.instance.Port) Value(com.cburch.logisim.data.Value)

Example 87 with Value

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

the class Multiplexer method propagate.

@Override
public void propagate(InstanceState state) {
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int inputs = 1 << select.getWidth();
    Value en = enable ? state.getPortValue(inputs + 1) : Value.TRUE;
    Value out;
    if (en == Value.FALSE) {
        Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
        Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
        out = Value.repeat(base, data.getWidth());
    } else if (en == Value.ERROR && state.isPortConnected(inputs + 1)) {
        out = Value.createError(data);
    } else {
        Value sel = state.getPortValue(inputs);
        if (sel.isFullyDefined()) {
            out = state.getPortValue(sel.toIntValue());
        } else if (sel.isErrorValue()) {
            out = Value.createError(data);
        } else {
            out = Value.createUnknown(data);
        }
    }
    state.setPort(inputs + (enable ? 2 : 1), out, Plexers.DELAY);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 88 with Value

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

the class Rom method propagate.

@Override
public void propagate(InstanceState state) {
    MemState myState = getState(state);
    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
    Value addrValue = state.getPortValue(ADDR);
    int addr = addrValue.toIntValue();
    if (!addrValue.isFullyDefined() || addr < 0)
        return;
    if (addr != myState.getCurrent()) {
        myState.setCurrent(addr);
        myState.scrollToShow(addr);
    }
    int val = myState.getContents().get(addr);
    state.setPort(DATA, Value.createKnown(dataBits, val), DELAY);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 89 with Value

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

the class Ram method propagate.

@Override
public void propagate(InstanceState state) {
    RamState myState = (RamState) getState(state);
    Object trigger = state.getAttributeValue(StdAttr.TRIGGER);
    Object bus = state.getAttributeValue(RamAttributes.ATTR_DBUS);
    boolean asynch = trigger.equals(StdAttr.TRIG_HIGH) || trigger.equals(StdAttr.TRIG_LOW);
    boolean edge = false;
    if (!asynch) {
        edge = myState.setClock(state.getPortValue(CLK), trigger);
    }
    boolean triggered = asynch || edge;
    boolean separate = bus == null ? false : bus.equals(RamAttributes.BUS_SEP);
    boolean outputEnabled = (!asynch || trigger.equals(StdAttr.TRIG_HIGH)) ? state.getPortValue(OE) != Value.FALSE : state.getPortValue(OE) == Value.FALSE;
    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);
    /* Set the outputs in tri-state in case of combined bus */
    if ((!separate && !outputEnabled) || (separate && asynch && !outputEnabled)) {
        state.setPort(DATA, Value.createUnknown(dataBits), DELAY);
    }
    if (!triggered && !asynch && outputEnabled) {
        state.setPort(DATA, Value.createKnown(dataBits, myState.GetCurrentData()), DELAY);
    }
    if (triggered) {
        Object be = state.getAttributeValue(RamAttributes.ATTR_ByteEnables);
        boolean byteEnables = be == null ? false : be.equals(RamAttributes.BUS_WITH_BYTEENABLES);
        int NrOfByteEnables = GetNrOfByteEnables(state.getAttributeSet());
        int ByteEnableIndex = ByteEnableIndex(state.getAttributeSet());
        boolean shouldStore = (!asynch || trigger.equals(StdAttr.TRIG_HIGH)) ? state.getPortValue(WE) != Value.FALSE : state.getPortValue(WE) == Value.FALSE;
        Value addrValue = state.getPortValue(ADDR);
        int addr = addrValue.toIntValue();
        if (!addrValue.isFullyDefined() || addr < 0) {
            return;
        }
        if (addr != myState.getCurrent()) {
            myState.setCurrent(addr);
            myState.scrollToShow(addr);
        }
        if (shouldStore) {
            int dataValue = state.getPortValue(!separate ? DATA : (asynch) ? ADIN : SDIN).toIntValue();
            int memValue = myState.getContents().get(addr);
            if (byteEnables) {
                int mask = 0xFF << (NrOfByteEnables - 1) * 8;
                for (int i = 0; i < NrOfByteEnables; i++) {
                    Value bitvalue = state.getPortValue(ByteEnableIndex + i);
                    boolean disabled = bitvalue == null ? false : bitvalue.equals(Value.FALSE);
                    if (disabled) {
                        dataValue &= ~mask;
                        dataValue |= (memValue & mask);
                    }
                    mask >>= 8;
                }
            }
            myState.getContents().set(addr, dataValue);
        }
        int val = myState.getContents().get(addr);
        int currentValue = myState.GetCurrentData();
        if (byteEnables) {
            int mask = 0xFF << (NrOfByteEnables - 1) * 8;
            for (int i = 0; i < NrOfByteEnables; i++) {
                Value bitvalue = state.getPortValue(ByteEnableIndex + i);
                boolean disabled = bitvalue == null ? false : bitvalue.equals(Value.FALSE);
                if (disabled) {
                    val &= ~mask;
                    val |= (currentValue & mask);
                }
                mask >>= 8;
            }
        }
        myState.SetCurrentData(val);
        if (outputEnabled) {
            state.setPort(DATA, Value.createKnown(dataBits, val), DELAY);
        }
    }
}
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