Search in sources :

Example 6 with BitWidth

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

the class CircuitWires method getWidth.

BitWidth getWidth(Location q) {
    BitWidth det = points.getWidth(q);
    if (det != BitWidth.UNKNOWN)
        return det;
    BundleMap bmap = getBundleMap();
    if (!bmap.isValid())
        return BitWidth.UNKNOWN;
    WireBundle qb = bmap.getBundleAt(q);
    if (qb != null && qb.isValid())
        return qb.getWidth();
    return BitWidth.UNKNOWN;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 7 with BitWidth

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

the class CircuitWires method computeBundleMap.

// To be called by getBundleMap only
private void computeBundleMap(BundleMap ret) {
    // create bundles corresponding to wires and tunnels
    connectWires(ret);
    connectTunnels(ret);
    connectPullResistors(ret);
    // merge any WireBundle objects united by previous steps
    for (Iterator<WireBundle> it = ret.getBundles().iterator(); it.hasNext(); ) {
        WireBundle b = it.next();
        WireBundle bpar = b.find();
        if (bpar != b) {
            // b isn't group's representative
            for (Location pt : b.points) {
                ret.setBundleAt(pt, bpar);
                bpar.points.add(pt);
            }
            bpar.addPullValue(b.getPullValue());
            it.remove();
        }
    }
    // make a WireBundle object for each end of a splitter
    for (Splitter spl : splitters) {
        List<EndData> ends = new ArrayList<EndData>(spl.getEnds());
        for (EndData end : ends) {
            Location p = end.getLocation();
            WireBundle pb = ret.createBundleAt(p);
            pb.setWidth(end.getWidth(), p);
        }
    }
    // based on components
    for (Location p : ret.getBundlePoints()) {
        WireBundle pb = ret.getBundleAt(p);
        BitWidth width = points.getWidth(p);
        if (width != BitWidth.UNKNOWN) {
            pb.setWidth(width, p);
        }
    }
    // determine the bundles at the end of each splitter
    for (Splitter spl : splitters) {
        List<EndData> ends = new ArrayList<EndData>(spl.getEnds());
        int index = -1;
        for (EndData end : ends) {
            index++;
            Location p = end.getLocation();
            WireBundle pb = ret.getBundleAt(p);
            if (pb != null) {
                pb.setWidth(end.getWidth(), p);
                spl.wire_data.end_bundle[index] = pb;
            }
        }
    }
    // unite threads going through splitters
    for (Splitter spl : splitters) {
        synchronized (spl) {
            SplitterAttributes spl_attrs = (SplitterAttributes) spl.getAttributeSet();
            byte[] bit_end = spl_attrs.bit_end;
            SplitterData spl_data = spl.wire_data;
            WireBundle from_bundle = spl_data.end_bundle[0];
            if (from_bundle == null || !from_bundle.isValid())
                continue;
            for (int i = 0; i < bit_end.length; i++) {
                int j = bit_end[i];
                if (j > 0) {
                    int thr = spl.bit_thread[i];
                    WireBundle to_bundle = spl_data.end_bundle[j];
                    WireThread[] to_threads = to_bundle.threads;
                    if (to_threads != null && to_bundle.isValid()) {
                        WireThread[] from_threads = from_bundle.threads;
                        if (i >= from_threads.length) {
                            throw new ArrayIndexOutOfBoundsException("from " + i + " of " + from_threads.length);
                        }
                        if (thr >= to_threads.length) {
                            throw new ArrayIndexOutOfBoundsException("to " + thr + " of " + to_threads.length);
                        }
                        from_threads[i].unite(to_threads[thr]);
                    }
                }
            }
        }
    }
    // merge any threads united by previous step
    for (WireBundle b : ret.getBundles()) {
        if (b.isValid() && b.threads != null) {
            for (int i = 0; i < b.threads.length; i++) {
                WireThread thr = b.threads[i].find();
                b.threads[i] = thr;
                thr.getBundles().add(new ThreadBundle(i, b));
            }
        }
    }
    // All threads are sewn together! Compute the exception set before
    // leaving
    Collection<WidthIncompatibilityData> exceptions = points.getWidthIncompatibilityData();
    if (exceptions != null && exceptions.size() > 0) {
        for (WidthIncompatibilityData wid : exceptions) {
            ret.addWidthIncompatibilityData(wid);
        }
    }
    for (WireBundle b : ret.getBundles()) {
        WidthIncompatibilityData e = b.getWidthIncompatibilityData();
        if (e != null)
            ret.addWidthIncompatibilityData(e);
    }
}
Also used : EndData(com.cburch.logisim.comp.EndData) ArrayList(java.util.ArrayList) BitWidth(com.cburch.logisim.data.BitWidth) Location(com.cburch.logisim.data.Location)

Example 8 with BitWidth

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

the class SplitterAttributes method setValue.

@Override
public <V> void setValue(Attribute<V> attr, V value) {
    if (attr == StdAttr.FACING) {
        Direction NewFacing = (Direction) value;
        if (facing.equals(NewFacing))
            return;
        facing = (Direction) value;
        configureOptions();
        parameters = null;
    } else if (attr == ATTR_FANOUT) {
        int newValue = ((Integer) value).intValue();
        byte[] bits = bit_end;
        for (int i = 0; i < bits.length; i++) {
            if (bits[i] >= newValue)
                bits[i] = (byte) (newValue - 1);
        }
        if (fanout == (byte) newValue)
            return;
        fanout = (byte) newValue;
        configureOptions();
        configureDefaults();
        parameters = null;
    } else if (attr == ATTR_WIDTH) {
        BitWidth width = (BitWidth) value;
        if (bit_end.length == width.getWidth())
            return;
        bit_end = new byte[width.getWidth()];
        configureOptions();
        configureDefaults();
    } else if (attr == ATTR_APPEARANCE) {
        AttributeOption appearance = (AttributeOption) value;
        if (appear.equals(appearance))
            return;
        appear = appearance;
        parameters = null;
    } else if (attr instanceof BitOutAttribute) {
        BitOutAttribute bitOutAttr = (BitOutAttribute) attr;
        int val;
        if (value instanceof Integer) {
            val = ((Integer) value).intValue();
        } else {
            val = ((BitOutOption) value).value + 1;
        }
        if (val >= 0 && val <= fanout) {
            if (bit_end[bitOutAttr.which] == (byte) val)
                return;
            bit_end[bitOutAttr.which] = (byte) val;
        } else
            return;
    } else {
        throw new IllegalArgumentException("unknown attribute " + attr);
    }
    fireAttributeValueChanged(attr, value, null);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) AttributeOption(com.cburch.logisim.data.AttributeOption)

Example 9 with BitWidth

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

the class ShiftRegister method configurePorts.

private void configurePorts(Instance instance) {
    BitWidth widthObj = instance.getAttributeValue(StdAttr.WIDTH);
    int width = widthObj.getWidth();
    Boolean parallelObj = instance.getAttributeValue(ATTR_LOAD);
    Bounds bds = instance.getBounds();
    Port[] ps;
    Integer lenObj = instance.getAttributeValue(ATTR_LENGTH);
    int len = lenObj == null ? 8 : lenObj.intValue();
    if (parallelObj == null || parallelObj.booleanValue()) {
        ps = new Port[6 + 2 * len - 1];
        ps[LD] = new Port(0, 30, Port.INPUT, 1);
        ps[LD].setToolTip(Strings.getter("shiftRegLoadTip"));
        for (int i = 0; i < len; i++) {
            ps[6 + 2 * i] = new Port(0, 90 + i * 20, Port.INPUT, width);
            if (i < (len - 1))
                ps[6 + 2 * i + 1] = new Port(SymbolWidth + 20, 90 + i * 20, Port.OUTPUT, width);
        }
    } else {
        ps = new Port[5];
    }
    ps[OUT] = new Port(SymbolWidth + 20, 70 + len * 20, Port.OUTPUT, width);
    ps[IN] = new Port(0, 80, Port.INPUT, width);
    ps[SH] = new Port(0, 40, Port.INPUT, 1);
    ps[CK] = new Port(0, 50, Port.INPUT, 1);
    ps[CLR] = new Port(0, 20, Port.INPUT, 1);
    ps[OUT].setToolTip(Strings.getter("shiftRegOutTip"));
    ps[SH].setToolTip(Strings.getter("shiftRegShiftTip"));
    ps[IN].setToolTip(Strings.getter("shiftRegInTip"));
    ps[CK].setToolTip(Strings.getter("shiftRegClockTip"));
    ps[CLR].setToolTip(Strings.getter("shiftRegClearTip"));
    instance.setPorts(ps);
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, bds.getX() + bds.getWidth() / 2, bds.getY() - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Port(com.cburch.logisim.instance.Port)

Example 10 with BitWidth

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

the class ShiftRegister method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    // draw boundary, label
    painter.drawLabel();
    int xpos = painter.getLocation().getX();
    int ypos = painter.getLocation().getY();
    BitWidth widObj = painter.getAttributeValue(StdAttr.WIDTH);
    int wid = widObj.getWidth();
    Integer lenObj = painter.getAttributeValue(ATTR_LENGTH);
    int len = lenObj == null ? 8 : lenObj.intValue();
    Boolean parallelObj = painter.getAttributeValue(ATTR_LOAD);
    Boolean Negedge = painter.getAttributeValue(StdAttr.EDGE_TRIGGER).equals(StdAttr.TRIG_FALLING);
    DrawControl(painter, xpos, ypos, len, wid, parallelObj, Negedge);
    ShiftRegisterData data = (ShiftRegisterData) painter.getData();
    /**
     * In the case data is null we assume that the
     * different value are null. This allow the user to
     * instantiate the shift register without simulation mode
     */
    if (data == null) {
        for (int stage = 0; stage < len; stage++) {
            DrawDataBlock(painter, xpos, ypos, len, wid, stage, null, parallelObj);
        }
    } else {
        for (int stage = 0; stage < len; stage++) {
            DrawDataBlock(painter, xpos, ypos, len, wid, stage, data.get(len - stage - 1), parallelObj);
        }
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

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