Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


  /** 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
View Full Code Here


  @Override
  public void propagate(InstanceState state) {
    // This is the same as with SimpleGrayCounter, except that we use the
    // StdAttr.WIDTH attribute to determine the bit width to work with.
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    CounterData cur = CounterData.get(state, width);
    boolean trigger = cur.updateClock(state.getPort(0));
    if (trigger) cur.setValue(GrayIncrementer.nextGray(cur.getValue()));
    state.setPort(1, cur.getValue(), 9);
  }
View Full Code Here

    painter.drawClock(0, Direction.EAST);
    painter.drawPort(1);
    painter.drawLabel();
   
    if (painter.getShowState()) {
      BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
      CounterData state = CounterData.get(painter, width);
      Bounds bds = painter.getBounds();
      GraphicsUtil.drawCenteredText(painter.getGraphics(),
          StringUtil.toHexString(width.getWidth(), state.getValue().toIntValue()),
          bds.getX() + bds.getWidth() / 2,
          bds.getY() + bds.getHeight() / 2);
    }
  }
View Full Code Here

    GraphicsUtil.switchToWidth(g, 2);
    FontMetrics fm = base.getFontMetrics(g.getFont());
    for (WidthIncompatibilityData ex : exceptions) {
      for (int i = 0; i < ex.size(); i++) {
        Location p = ex.getPoint(i);
        BitWidth w = ex.getBitWidth(i);

        // ensure it hasn't already been drawn
        boolean drawn = false;
        for (int j = 0; j < i; j++) {
          if (ex.getPoint(j).equals(p)) { drawn = true; break; }
        }
        if (drawn) continue;

        // compute the caption combining all similar points
        String caption = "" + w.getWidth();
        for (int j = i + 1; j < ex.size(); j++) {
          if (ex.getPoint(j).equals(p)) { caption += "/" + ex.getBitWidth(j); break; }
        }
        g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
        g.drawString(caption, p.getX() + 5, p.getY() + 2 + fm.getAscent());
View Full Code Here

    WidthIncompatibilityData o = (WidthIncompatibilityData) other;
    if (this.size() != o.size()) return false;
    for (int i = 0; i < this.size(); i++) {
      Location p = this.getPoint(i);
      BitWidth w = this.getBitWidth(i);
      boolean matched = false;
      for (int j = 0; j < o.size(); j++) {
        Location q = this.getPoint(j);
        BitWidth x = this.getBitWidth(j);
        if (p.equals(q) && w.equals(x)) { matched = true; break; }
      }
      if (!matched) return false;
    }
    return true;
View Full Code Here

    return ret != null && !ret.equals("") ? ret : null;
  }

  @Override
  public Value getLogValue(InstanceState state, Object option) {
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    if (dataWidth == null) dataWidth = BitWidth.create(0);
    RegisterData data = (RegisterData) state.getData();
    if (data == null) return Value.createKnown(dataWidth, 0);
    return Value.createKnown(dataWidth, data.value);
  }
View Full Code Here

    return loc >= 0;
  }
 
  private int computeStage(InstanceState state, MouseEvent e) {
    Integer lenObj = state.getAttributeValue(ShiftRegister.ATTR_LENGTH);
    BitWidth widObj = state.getAttributeValue(StdAttr.WIDTH);
    Boolean loadObj = state.getAttributeValue(ShiftRegister.ATTR_LOAD);
    Bounds bds = state.getInstance().getBounds();

    int y = bds.getY();
    String label = state.getAttributeValue(StdAttr.LABEL);
    if (label == null || label.equals("")) y += bds.getHeight() / 2;
    else y += 3 * bds.getHeight() / 4;
    y = e.getY() - y;
    if (y <= -6 || y >= 8) return -1;
   
    int x = e.getX() - (bds.getX() + 15);
    if (!loadObj.booleanValue() || widObj.getWidth() > 4) return -1;
    if (x < 0 || x >= lenObj.intValue() * 10) return -1;
    return x / 10;
  }
View Full Code Here

 
  @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);
View Full Code Here

        state.fireInvalidated();
      }
    } else {
      try {
        int val = Integer.parseInt("" + e.getKeyChar(), 16);
        BitWidth widObj = state.getAttributeValue(StdAttr.WIDTH);
        if ((val & ~widObj.getMask()) != 0) return;
        Value valObj = Value.createKnown(widObj, val);
        ShiftRegisterData data = (ShiftRegisterData) state.getData();
        int i = data.getLength() - 1 - loc;
        if (!data.get(i).equals(valObj)) {
          data.set(i, valObj);
View Full Code Here

      .rotate(Direction.EAST, attrs.getValue(StdAttr.FACING), 0, 0);
  }

  @Override
  public void propagate(InstanceState state) {
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    state.setPort(0, Value.repeat(Value.FALSE, width.getWidth()), 1);
  }
View Full Code Here

TOP

Related Classes of com.cburch.logisim.data.BitWidth

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.