Search in sources :

Example 51 with BitWidth

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

the class bin2bcd method updatePorts.

private void updatePorts(Instance instance) {
    BitWidth nrofbits = instance.getAttributeValue(bin2bcd.ATTR_BinBits);
    int NrOfPorts = (int) (Math.log10(1 << nrofbits.getWidth()) + 1.0);
    Port[] ps = new Port[NrOfPorts + 1];
    ps[BINin] = new Port((int) (-0.5 * InnerDistance), 0, Port.INPUT, bin2bcd.ATTR_BinBits);
    ps[BINin].setToolTip(Strings.getter("BinairyInputTip"));
    for (int i = NrOfPorts; i > 0; i--) {
        ps[i] = new Port((NrOfPorts - i) * InnerDistance, -20, Port.OUTPUT, 4);
        int value = (int) Math.pow(10.0, i - 1);
        ps[i].setToolTip(Strings.getter(Integer.toString(value)));
    }
    instance.setPorts(ps);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Port(com.cburch.logisim.instance.Port)

Example 52 with BitWidth

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

the class bin2bcd method getHDLName.

@Override
public String getHDLName(AttributeSet attrs) {
    StringBuffer CompleteName = new StringBuffer();
    BitWidth nrofbits = attrs.getValue(bin2bcd.ATTR_BinBits);
    int NrOfPorts = (int) (Math.log10(1 << nrofbits.getWidth()) + 1.0);
    CompleteName.append(CorrectLabel.getCorrectLabel(this.getName()));
    CompleteName.append("_" + Integer.toString(NrOfPorts) + "_bcd_ports");
    return CompleteName.toString();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth)

Example 53 with BitWidth

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

the class bin2bcdHDLGeneratorFactory method GetModuleFunctionality.

@Override
public ArrayList<String> GetModuleFunctionality(Netlist TheNetlist, AttributeSet attrs, FPGAReport Reporter, String HDLType) {
    ArrayList<String> Contents = new ArrayList<String>();
    BitWidth nrofbits = attrs.getValue(bin2bcd.ATTR_BinBits);
    int NrOfPorts = (int) (Math.log10(1 << nrofbits.getWidth()) + 1.0);
    if (HDLType.equals(VHDL)) {
        switch(NrOfPorts) {
            case 2:
                Contents.add("   s_level_0(6 DOWNTO " + NrOfBitsStr + ") <= (OTHERS => '0');");
                Contents.add("   s_level_0(" + NrOfBitsStr + "-1 DOWNTO 0) <= BinValue;");
                Contents.add("   s_level_1(2 DOWNTO 0) <= s_level_0(2 DOWNTO 0);");
                Contents.add("   s_level_2(1 DOWNTO 0) <= s_level_1(1 DOWNTO 0);");
                Contents.add("   s_level_2(6)          <= s_level_1(6);");
                Contents.add("   s_level_3(6 DOWNTO 5) <= s_level_2(6 DOWNTO 5);");
                Contents.add("   s_level_3(0)          <= s_level_2(0);");
                Contents.add("   ");
                Contents.add("   BCD1  <= s_level_3( 3 DOWNTO 0);");
                Contents.add("   BCD10 <= \"0\"&s_level_3(6 DOWNTO 4);");
                Contents.addAll(GetAdd3Block("s_level_0", 6, "s_level_1", 6, "C1"));
                Contents.addAll(GetAdd3Block("s_level_1", 5, "s_level_2", 5, "C2"));
                Contents.addAll(GetAdd3Block("s_level_2", 4, "s_level_3", 4, "C3"));
                break;
            case 3:
                Contents.add("   s_level_0(10 DOWNTO " + NrOfBitsStr + ") <= (OTHERS => '0');");
                Contents.add("   s_level_0(" + NrOfBitsStr + "-1 DOWNTO 0) <= BinValue;");
                Contents.add("   s_level_1(10)          <= s_level_0(10);");
                Contents.add("   s_level_1( 5 DOWNTO 0) <= s_level_0( 5 DOWNTO 0);");
                Contents.add("   s_level_2(10 DOWNTO 9) <= s_level_1(10 DOWNTO 9);");
                Contents.add("   s_level_2( 4 DOWNTO 0) <= s_level_1( 4 DOWNTO 0);");
                Contents.add("   s_level_3(10 DOWNTO 8) <= s_level_2(10 DOWNTO 8);");
                Contents.add("   s_level_3( 3 DOWNTO 0) <= s_level_2( 3 DOWNTO 0);");
                Contents.add("   s_level_4( 2 DOWNTO 0) <= s_level_3( 2 DOWNTO 0);");
                Contents.add("   s_level_5(10)          <= s_level_4(10);");
                Contents.add("   s_level_5( 1 DOWNTO 0) <= s_level_4( 1 DOWNTO 0);");
                Contents.add("   s_level_6(10 DOWNTO 9) <= s_level_5(10 DOWNTO 9);");
                Contents.add("   s_level_6(0)           <= s_level_5(0);");
                Contents.add("   ");
                Contents.add("   BCD1   <= s_level_6( 3 DOWNTO 0 );");
                Contents.add("   BCD10  <= s_level_6( 7 DOWNTO 4 );");
                Contents.add("   BCD100 <= \"0\"&s_level_6(10 DOWNTO 8);");
                Contents.addAll(GetAdd3Block("s_level_0", 9, "s_level_1", 9, "C0"));
                Contents.addAll(GetAdd3Block("s_level_1", 8, "s_level_2", 8, "C1"));
                Contents.addAll(GetAdd3Block("s_level_2", 7, "s_level_3", 7, "C2"));
                Contents.addAll(GetAdd3Block("s_level_3", 6, "s_level_4", 6, "C3"));
                Contents.addAll(GetAdd3Block("s_level_4", 5, "s_level_5", 5, "C4"));
                Contents.addAll(GetAdd3Block("s_level_5", 4, "s_level_6", 4, "C5"));
                Contents.addAll(GetAdd3Block("s_level_3", 10, "s_level_4", 10, "C6"));
                Contents.addAll(GetAdd3Block("s_level_4", 9, "s_level_5", 9, "C7"));
                Contents.addAll(GetAdd3Block("s_level_5", 8, "s_level_6", 8, "C8"));
                break;
            case 4:
                Contents.add("   s_level_0(15 DOWNTO " + NrOfBitsStr + ") <= (OTHERS => '0');");
                Contents.add("   s_level_0(" + NrOfBitsStr + "-1 DOWNTO 0) <= BinValue;");
                Contents.add("   s_level_1(15 DOWNTO 14)  <= s_level_0(15 DOWNTO 14);");
                Contents.add("   s_level_1( 9 DOWNTO  0)  <= s_level_0( 9 DOWNTO  0);");
                Contents.add("   s_level_2(15 DOWNTO 13)  <= s_level_1(15 DOWNTO 13);");
                Contents.add("   s_level_2( 8 DOWNTO  0)  <= s_level_1( 8 DOWNTO  0);");
                Contents.add("   s_level_3(15 DOWNTO 12)  <= s_level_2(15 DOWNTO 12);");
                Contents.add("   s_level_3( 7 DOWNTO  0)  <= s_level_2( 7 DOWNTO  0);");
                Contents.add("   s_level_4(15)            <= s_level_3(15);");
                Contents.add("   s_level_4( 6 DOWNTO  0)  <= s_level_3( 6 DOWNTO  0);");
                Contents.add("   s_level_5(15 DOWNTO 14)  <= s_level_4(15 DOWNTO 14);");
                Contents.add("   s_level_5( 5 DOWNTO  0)  <= s_level_4( 5 DOWNTO  0);");
                Contents.add("   s_level_6(15 DOWNTO 13)  <= s_level_5(15 DOWNTO 13);");
                Contents.add("   s_level_6( 4 DOWNTO  0)  <= s_level_5( 4 DOWNTO  0);");
                Contents.add("   s_level_7( 3 DOWNTO  0)  <= s_level_6( 3 DOWNTO  0);");
                Contents.add("   s_level_8(15)            <= s_level_7(15);");
                Contents.add("   s_level_8( 2 DOWNTO  0)  <= s_level_7( 2 DOWNTO  0);");
                Contents.add("   s_level_9(15 DOWNTO 14)  <= s_level_8(15 DOWNTO 14);");
                Contents.add("   s_level_9( 1 DOWNTO  0)  <= s_level_8( 1 DOWNTO  0);");
                Contents.add("   s_level_10(15 DOWNTO 13) <= s_level_9(15 DOWNTO 13);");
                Contents.add("   s_level_10(0)            <= s_level_9(0);");
                Contents.add("   ");
                Contents.add("   BCD1    <= s_level_10( 3 DOWNTO  0 );");
                Contents.add("   BCD10   <= s_level_10( 7 DOWNTO  4 );");
                Contents.add("   BCD100  <= s_level_10(11 DOWNTO  8);");
                Contents.add("   BCD1000 <= s_level_10(15 DOWNTO 12);");
                Contents.addAll(GetAdd3Block("s_level_0", 13, "s_level_1", 13, "C0"));
                Contents.addAll(GetAdd3Block("s_level_1", 12, "s_level_2", 12, "C1"));
                Contents.addAll(GetAdd3Block("s_level_2", 11, "s_level_3", 11, "C2"));
                Contents.addAll(GetAdd3Block("s_level_3", 10, "s_level_4", 10, "C3"));
                Contents.addAll(GetAdd3Block("s_level_4", 9, "s_level_5", 9, "C4"));
                Contents.addAll(GetAdd3Block("s_level_5", 8, "s_level_6", 8, "C5"));
                Contents.addAll(GetAdd3Block("s_level_6", 7, "s_level_7", 7, "C6"));
                Contents.addAll(GetAdd3Block("s_level_7", 6, "s_level_8", 6, "C7"));
                Contents.addAll(GetAdd3Block("s_level_8", 5, "s_level_9", 5, "C8"));
                Contents.addAll(GetAdd3Block("s_level_9", 4, "s_level_10", 4, "C9"));
                Contents.addAll(GetAdd3Block("s_level_3", 14, "s_level_4", 14, "C10"));
                Contents.addAll(GetAdd3Block("s_level_4", 13, "s_level_5", 13, "C11"));
                Contents.addAll(GetAdd3Block("s_level_5", 12, "s_level_6", 12, "C12"));
                Contents.addAll(GetAdd3Block("s_level_6", 11, "s_level_7", 11, "C13"));
                Contents.addAll(GetAdd3Block("s_level_7", 10, "s_level_8", 10, "C14"));
                Contents.addAll(GetAdd3Block("s_level_8", 9, "s_level_9", 9, "C15"));
                Contents.addAll(GetAdd3Block("s_level_9", 8, "s_level_10", 8, "C16"));
                Contents.addAll(GetAdd3Block("s_level_6", 15, "s_level_7", 15, "C17"));
                Contents.addAll(GetAdd3Block("s_level_7", 14, "s_level_8", 14, "C18"));
                Contents.addAll(GetAdd3Block("s_level_8", 13, "s_level_9", 13, "C19"));
                Contents.addAll(GetAdd3Block("s_level_9", 12, "s_level_10", 12, "C20"));
                break;
        }
    } else {
        Reporter.AddFatalError("Strange, this should not happen as Verilog is not yet supported!\n");
    }
    return Contents;
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) ArrayList(java.util.ArrayList)

Example 54 with BitWidth

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

the class InstanceComponent method computeEnds.

private void computeEnds() {
    List<Port> ports = portList;
    EndData[] esOld = endArray;
    int esOldLength = esOld == null ? 0 : esOld.length;
    EndData[] es = esOld;
    if (es == null || es.length != ports.size()) {
        es = new EndData[ports.size()];
        if (esOldLength > 0) {
            int toCopy = Math.min(esOldLength, es.length);
            System.arraycopy(esOld, 0, es, 0, toCopy);
        }
    }
    HashSet<Attribute<BitWidth>> wattrs = null;
    boolean toolTipFound = false;
    ArrayList<EndData> endsChangedOld = null;
    ArrayList<EndData> endsChangedNew = null;
    Iterator<Port> pit = ports.iterator();
    for (int i = 0; pit.hasNext() || i < esOldLength; i++) {
        Port p = pit.hasNext() ? pit.next() : null;
        EndData oldEnd = i < esOldLength ? esOld[i] : null;
        EndData newEnd = p == null ? null : p.toEnd(loc, attrs);
        if (oldEnd == null || !oldEnd.equals(newEnd)) {
            if (newEnd != null)
                es[i] = newEnd;
            if (endsChangedOld == null) {
                endsChangedOld = new ArrayList<EndData>();
                endsChangedNew = new ArrayList<EndData>();
            }
            endsChangedOld.add(oldEnd);
            endsChangedNew.add(newEnd);
        }
        if (p != null) {
            Attribute<BitWidth> attr = p.getWidthAttribute();
            if (attr != null) {
                if (wattrs == null) {
                    wattrs = new HashSet<Attribute<BitWidth>>();
                }
                wattrs.add(attr);
            }
            if (p.getToolTip() != null)
                toolTipFound = true;
        }
    }
    if (!attrListenRequested) {
        HashSet<Attribute<BitWidth>> oldWattrs = widthAttrs;
        if (wattrs == null && oldWattrs != null) {
            getAttributeSet().removeAttributeListener(this);
        } else if (wattrs != null && oldWattrs == null) {
            getAttributeSet().addAttributeListener(this);
        }
    }
    if (es != esOld) {
        endArray = es;
        endList = new UnmodifiableList<EndData>(es);
    }
    widthAttrs = wattrs;
    hasToolTips = toolTipFound;
    if (endsChangedOld != null) {
        fireEndsChanged(endsChangedOld, endsChangedNew);
    }
}
Also used : EndData(com.cburch.logisim.comp.EndData) Attribute(com.cburch.logisim.data.Attribute) BitWidth(com.cburch.logisim.data.BitWidth)

Example 55 with BitWidth

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

the class CounterPoker method keyTyped.

/**
 * Processes a key by just adding it onto the end of the current value.
 */
@Override
public void keyTyped(InstanceState state, KeyEvent e) {
    // convert it to a hex digit; if it isn't a hex digit, abort.
    int val = Character.digit(e.getKeyChar(), 16);
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    if (val < 0 || (val & width.getMask()) != val)
        return;
    // compute the next value
    CounterData cur = CounterData.get(state, width);
    int newVal = (cur.getValue().toIntValue() * 16 + val) & width.getMask();
    Value newValue = Value.createKnown(width, newVal);
    cur.setValue(newValue);
    state.fireInvalidated();
// You might be tempted to propagate the value immediately here, using
// state.setPort. However, the circuit may currently be propagating in
// another thread, and invoking setPort directly could interfere with
// that. Using fireInvalidated notifies the propagation thread to
// invoke propagate on the counter at its next opportunity.
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Value(com.cburch.logisim.data.Value)

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