Search in sources :

Example 86 with BitWidth

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

the class ShiftRegisterPoker method mouseReleased.

@Override
public void mouseReleased(InstanceState state, MouseEvent e) {
    int oldLoc = loc;
    if (oldLoc < 0)
        return;
    BitWidth widObj = state.getAttributeValue(StdAttr.WIDTH);
    if (widObj.equals(BitWidth.ONE)) {
        int newLoc = computeStage(state, e);
        if (oldLoc == newLoc) {
            ShiftRegisterData data = (ShiftRegisterData) state.getData();
            int i = data.getLength() - 1 - loc;
            Value v = data.get(i);
            if (v == Value.FALSE)
                v = Value.TRUE;
            else
                v = Value.FALSE;
            data.set(i, v);
            state.fireInvalidated();
        }
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 87 with BitWidth

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

the class ShiftRegisterPoker method computeStage.

private int computeStage(InstanceState state, MouseEvent e) {
    BitWidth widObj = state.getAttributeValue(StdAttr.WIDTH);
    Bounds bds = state.getInstance().getBounds();
    int len = (widObj.getWidth() + 3) / 4;
    int boxXpos = ((ShiftRegister.SymbolWidth - 30) / 2 + 30) - (len * 4);
    int boxXend = boxXpos + 2 + len * 8;
    int y = e.getY() - bds.getY() - 80;
    if (y < 0)
        return -1;
    int x = e.getX() - bds.getX() - 10;
    if ((x < boxXpos) || (x > boxXend))
        return -1;
    return (y / 20);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds)

Example 88 with BitWidth

use of com.cburch.logisim.data.BitWidth 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 89 with BitWidth

use of com.cburch.logisim.data.BitWidth 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 90 with BitWidth

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

the class Decoder method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = instance.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Port[] ps = new Port[outputs + (enable ? 2 : 1)];
    if (outputs == 2) {
        Location end0;
        Location end1;
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            int y = facing == Direction.NORTH ? -10 : 10;
            if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
                end0 = Location.create(-30, y);
                end1 = Location.create(-10, y);
            } else {
                end0 = Location.create(10, y);
                end1 = Location.create(30, y);
            }
        } else {
            int x = facing == Direction.WEST ? -10 : 10;
            if (selectLoc == Plexers.SELECT_TOP_RIGHT) {
                end0 = Location.create(x, 10);
                end1 = Location.create(x, 30);
            } else {
                end0 = Location.create(x, -30);
                end1 = Location.create(x, -10);
            }
        }
        ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, 1);
        ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, 1);
    } else {
        int dx;
        int ddx;
        int dy;
        int ddy;
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            dy = facing == Direction.NORTH ? -20 : 20;
            ddy = 0;
            dx = selectLoc == Plexers.SELECT_TOP_RIGHT ? -10 * outputs : 0;
            ddx = 10;
        } else {
            dx = facing == Direction.WEST ? -20 : 20;
            ddx = 0;
            dy = selectLoc == Plexers.SELECT_TOP_RIGHT ? 0 : -10 * outputs;
            ddy = 10;
        }
        for (int i = 0; i < outputs; i++) {
            ps[i] = new Port(dx, dy, Port.OUTPUT, 1);
            dx += ddx;
            dy += ddy;
        }
    }
    Location en = Location.create(0, 0).translate(facing, -10);
    ps[outputs] = new Port(0, 0, Port.INPUT, select.getWidth());
    if (enable) {
        ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    for (int i = 0; i < outputs; i++) {
        ps[i].setToolTip(Strings.getter("decoderOutTip", "" + i));
    }
    ps[outputs].setToolTip(Strings.getter("decoderSelectTip"));
    if (enable) {
        ps[outputs + 1].setToolTip(Strings.getter("decoderEnableTip"));
    }
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Aggregations

BitWidth (com.cburch.logisim.data.BitWidth)106 Value (com.cburch.logisim.data.Value)30 Bounds (com.cburch.logisim.data.Bounds)21 Direction (com.cburch.logisim.data.Direction)20 Location (com.cburch.logisim.data.Location)16 Graphics (java.awt.Graphics)15 Port (com.cburch.logisim.instance.Port)12 EndData (com.cburch.logisim.comp.EndData)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Font (java.awt.Font)3 FontMetrics (java.awt.FontMetrics)3 AttributeOption (com.cburch.logisim.data.AttributeOption)2 Graphics2D (java.awt.Graphics2D)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 WidthIncompatibilityData (com.cburch.logisim.circuit.WidthIncompatibilityData)1 Attribute (com.cburch.logisim.data.Attribute)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Dimension (java.awt.Dimension)1