Search in sources :

Example 31 with BitWidth

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

the class Demultiplexer method updatePorts.

private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Object selectLoc = instance.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    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 ? 3 : 2)];
    Location sel;
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    if (outputs == 2) {
        Location end0;
        Location end1;
        if (facing == Direction.WEST) {
            end0 = Location.create(-30, -10);
            end1 = Location.create(-30, 10);
            sel = Location.create(-20, selMult * 20);
        } else if (facing == Direction.NORTH) {
            end0 = Location.create(-10, -30);
            end1 = Location.create(10, -30);
            sel = Location.create(selMult * -20, -20);
        } else if (facing == Direction.SOUTH) {
            end0 = Location.create(-10, 30);
            end1 = Location.create(10, 30);
            sel = Location.create(selMult * -20, 20);
        } else {
            end0 = Location.create(30, -10);
            end1 = Location.create(30, 10);
            sel = Location.create(20, selMult * 20);
        }
        ps[0] = new Port(end0.getX(), end0.getY(), Port.OUTPUT, data.getWidth());
        ps[1] = new Port(end1.getX(), end1.getY(), Port.OUTPUT, data.getWidth());
    } else {
        int dx = -(outputs / 2) * 10;
        int ddx = 10;
        int dy = dx;
        int ddy = 10;
        if (facing == Direction.WEST) {
            dx = -40;
            ddx = 0;
            sel = Location.create(-20, selMult * (dy + 10 * outputs));
        } else if (facing == Direction.NORTH) {
            dy = -40;
            ddy = 0;
            sel = Location.create(selMult * dx, -20);
        } else if (facing == Direction.SOUTH) {
            dy = 40;
            ddy = 0;
            sel = Location.create(selMult * dx, 20);
        } else {
            dx = 40;
            ddx = 0;
            sel = Location.create(20, selMult * (dy + 10 * outputs));
        }
        for (int i = 0; i < outputs; i++) {
            ps[i] = new Port(dx, dy, Port.OUTPUT, data.getWidth());
            dx += ddx;
            dy += ddy;
        }
    }
    Location en = sel.translate(facing, -10);
    ps[outputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
    if (enable) {
        ps[outputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    ps[ps.length - 1] = new Port(0, 0, Port.INPUT, data.getWidth());
    for (int i = 0; i < outputs; i++) {
        ps[i].setToolTip(Strings.getter("demultiplexerOutTip", "" + i));
    }
    ps[outputs].setToolTip(Strings.getter("demultiplexerSelectTip"));
    if (enable) {
        ps[outputs + 1].setToolTip(Strings.getter("demultiplexerEnableTip"));
    }
    ps[ps.length - 1].setToolTip(Strings.getter("demultiplexerInTip"));
    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)

Example 32 with BitWidth

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

the class Demultiplexer method propagate.

@Override
public void propagate(InstanceState state) {
    // get attributes
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    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();
    Value en = enable ? state.getPortValue(outputs + 1) : Value.TRUE;
    // determine output values
    // the default output
    Value others;
    if (threeState.booleanValue()) {
        others = Value.createUnknown(data);
    } else {
        others = Value.createKnown(data, 0);
    }
    // the special output
    int outIndex = -1;
    Value out = null;
    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 = state.getPortValue(outputs + (enable ? 2 : 1));
        } 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 33 with BitWidth

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

the class Multiplexer method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    Bounds bds = painter.getBounds();
    if (select.getWidth() == 1) {
        if (facing == Direction.EAST || facing == Direction.WEST) {
            Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing, 10);
        } else {
            Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing, 10);
        }
    } else {
        Plexers.drawTrapezoid(painter.getGraphics(), bds, facing, 20);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 34 with BitWidth

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

the class PriorityEncoder method propagate.

@Override
public void propagate(InstanceState state) {
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    int n = 1 << select.getWidth();
    boolean enabled = state.getPortValue(n + EN_IN) != Value.FALSE;
    int out = -1;
    Value outDefault;
    if (enabled) {
        outDefault = Value.createUnknown(select);
        for (int i = n - 1; i >= 0; i--) {
            if (state.getPortValue(i) == Value.TRUE) {
                out = i;
                break;
            }
        }
    } else {
        Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
        Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
        outDefault = Value.repeat(base, select.getWidth());
    }
    if (out < 0) {
        state.setPort(n + OUT, outDefault, Plexers.DELAY);
        state.setPort(n + EN_OUT, enabled ? Value.TRUE : Value.FALSE, Plexers.DELAY);
        state.setPort(n + GS, Value.FALSE, Plexers.DELAY);
    } else {
        state.setPort(n + OUT, Value.createKnown(select, out), Plexers.DELAY);
        state.setPort(n + EN_OUT, Value.FALSE, Plexers.DELAY);
        state.setPort(n + GS, Value.TRUE, Plexers.DELAY);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

Example 35 with BitWidth

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

the class PriorityEncoder method updatePorts.

private void updatePorts(Instance instance) {
    Object dir = instance.getAttributeValue(StdAttr.FACING);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    int n = 1 << select.getWidth();
    Port[] ps = new Port[n + 4];
    if (dir == Direction.NORTH || dir == Direction.SOUTH) {
        int x = -5 * n + 10;
        int y = dir == Direction.NORTH ? 40 : -40;
        for (int i = 0; i < n; i++) {
            ps[i] = new Port(x + 10 * i, y, Port.INPUT, 1);
        }
        ps[n + OUT] = new Port(0, 0, Port.OUTPUT, select.getWidth());
        ps[n + EN_IN] = new Port(x + 10 * n, y / 2, Port.INPUT, 1);
        ps[n + EN_OUT] = new Port(x - 10, y / 2, Port.OUTPUT, 1);
        ps[n + GS] = new Port(10, 0, Port.OUTPUT, 1);
    } else {
        int x = dir == Direction.EAST ? -40 : 40;
        int y = -5 * n + 10;
        for (int i = 0; i < n; i++) {
            ps[i] = new Port(x, y + 10 * i, Port.INPUT, 1);
        }
        ps[n + OUT] = new Port(0, 0, Port.OUTPUT, select.getWidth());
        ps[n + EN_IN] = new Port(x / 2, y + 10 * n, Port.INPUT, 1);
        ps[n + EN_OUT] = new Port(x / 2, y - 10, Port.OUTPUT, 1);
        ps[n + GS] = new Port(0, 10, Port.OUTPUT, 1);
    }
    for (int i = 0; i < n; i++) {
        ps[i].setToolTip(Strings.getter("priorityEncoderInTip", "" + i));
    }
    ps[n + OUT].setToolTip(Strings.getter("priorityEncoderOutTip"));
    ps[n + EN_IN].setToolTip(Strings.getter("priorityEncoderEnableInTip"));
    ps[n + EN_OUT].setToolTip(Strings.getter("priorityEncoderEnableOutTip"));
    ps[n + GS].setToolTip(Strings.getter("priorityEncoderGroupSignalTip"));
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

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