Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


      instance.fireInvalidated();
    }
  }
 
  private void configurePorts(Instance instance) {
    BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
    int outWidth = computeOutputBits(inWidth.getWidth() - 1);

    Port[] ps = new Port[3];
    ps[0] = new Port(-2020, Port.OUTPUT, BitWidth.ONE);
    ps[1] = new Port0,   0, Port.OUTPUT, BitWidth.create(outWidth));
    ps[2] = new Port(-40,   0, Port.INPUT,  inWidth);
View Full Code Here


    }
  }

  private void updatePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    BitWidth data = instance.getAttributeValue(StdAttr.WIDTH);
    BitWidth group = instance.getAttributeValue(GROUP_ATTR);
    int groups = (data.getWidth() + group.getWidth() - 1) / group.getWidth() - 1;
    int selectBits = 1;
    if (groups > 0) {
      while (groups != 1) { groups >>= 1; selectBits++; }
    }
    BitWidth select = BitWidth.create(selectBits);

    Location inPt;
    Location selPt;
    if (facing == Direction.WEST) {
      inPt  = Location.create(30, 0);
      selPt = Location.create(10, 10);
    } else if (facing == Direction.NORTH) {
      inPt  = Location.create0, 30);
      selPt = Location.create(-10, 10);
    } else if (facing == Direction.SOUTH) {
      inPt  = Location.create0, -30);
      selPt = Location.create(-10, -10);
    } else {
      inPt  = Location.create(-30, 0);
      selPt = Location.create(-10, 10);
    }
   
    Port[] ps = new Port[3];
    ps[0] = new Port(0, 0, Port.OUTPUT, group.getWidth());
    ps[1] = new Port(inPt.getX(), inPt.getY(), Port.INPUT, data.getWidth());
    ps[2] = new Port(selPt.getX(), selPt.getY(), Port.INPUT, select.getWidth());
    ps[0].setToolTip(Strings.getter("bitSelectorOutputTip"));
    ps[1].setToolTip(Strings.getter("bitSelectorDataTip"));
    ps[2].setToolTip(Strings.getter("bitSelectorSelectTip"));
    instance.setPorts(ps);
  }
View Full Code Here

  @Override
  public void propagate(InstanceState state) {
    Value data = state.getPort(1);
    Value select = state.getPort(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);
View Full Code Here

      instance.recomputeBounds();
    }
  }
 
  private void configurePorts(Instance instance) {
    BitWidth inWidth = instance.getAttributeValue(StdAttr.WIDTH);
    int inputs = instance.getAttributeValue(NUM_INPUTS).intValue();
    int outWidth = computeOutputBits(inWidth.getWidth(), inputs);

    int y;
    int dy = 10;
    switch (inputs) {
    case 1: y = 0; break;
View Full Code Here

    }
  }

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

    Object onUndefined = opts.getValue(Options.ATTR_GATE_UNDEFINED);
    boolean errorIfUndefined = onUndefined.equals(Options.GATE_UNDEFINED_ERROR);
    Value repaired;
    if (errorIfUndefined) {
      int vw = v.getWidth();
      BitWidth w = state.getAttributeValue(StdAttr.WIDTH);
      int ww = w.getWidth();
      if (vw == ww && v.isFullyDefined()) return v;
      Value[] vs = new Value[w.getWidth()];
      for (int i = 0; i < vs.length; i++) {
        Value ini = i < vw ? v.get(i) : Value.ERROR;
        vs[i] = ini.isFullyDefined() ? ini : Value.ERROR;
      }
      repaired = Value.create(vs);
View Full Code Here

      configurePorts(instance);
    }
  }
 
  private void configurePorts(Instance instance) {
    BitWidth dataWid = instance.getAttributeValue(StdAttr.WIDTH);
    int data = dataWid == null ? 32 : dataWid.getWidth();
    int shift = 1;
    while ((1 << shift) < data) shift++;

    Port[] ps = new Port[3];
    ps[IN0]   = new Port(-40, -10, Port.INPUT,  data);
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    // compute output
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);
    int bits = dataWidth == null ? 32 : dataWidth.getWidth();
    Value vx = state.getPort(IN0);
    Value vd = state.getPort(IN1);
    Value vy; // y will by x shifted by d
    if (vd.isFullyDefined() && vx.getWidth() == bits) {
      int d = vd.toIntValue();
      Object shift = state.getAttributeValue(ATTR_SHIFT);
      if (d == 0) {
        vy = vx;
      } else if (vx.isFullyDefined()) {
        int x = vx.toIntValue();
        int y;
        if (shift == SHIFT_LOGICAL_RIGHT) {
          y = x >>> d;
        } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
          if (d >= bits) d = bits - 1;
          y = x >> d | ((x << (32 - bits)) >> (32 - bits + d));
        } else if (shift == SHIFT_ROLL_RIGHT) {
          if (d >= bits) d -= bits;
          y = (x >>> d) | (x << (bits - d));
        } else if (shift == SHIFT_ROLL_LEFT) {
          if (d >= bits) d -= bits;
          y = (x << d) | (x >>> (bits - d));
        } else { // SHIFT_LOGICAL_LEFT
          y = x << d;
        }
        vy = Value.createKnown(dataWidth, y);
      } else {
        Value[] x = vx.getAll();
        Value[] y = new Value[bits];
        if (shift == SHIFT_LOGICAL_RIGHT) {
          if (d >= bits) d = bits;
          System.arraycopy(x, d, y, 0, bits - d);
          Arrays.fill(y, bits - d, bits, Value.FALSE);
        } else if (shift == SHIFT_ARITHMETIC_RIGHT) {
          if (d >= bits) d = bits;
          System.arraycopy(x, d, y, 0, x.length - d);
          Arrays.fill(y, bits - d, y.length, x[bits - 1]);
        } else if (shift == SHIFT_ROLL_RIGHT) {
          if (d >= bits) d -= bits;
          System.arraycopy(x, d, y, 0, bits - d);
          System.arraycopy(x, 0, y, bits - d, d);
        } else if (shift == SHIFT_ROLL_LEFT) {
          if (d >= bits) d -= bits;
          System.arraycopy(x, x.length - d, y, 0, d);
          System.arraycopy(x, 0, y, d, bits - d);
        } else { // SHIFT_LOGICAL_LEFT
          if (d >= bits) d = bits;
          Arrays.fill(y, 0, d, Value.FALSE);
          System.arraycopy(x, 0, y, d, bits - d);
        }
        vy = Value.create(y);
      }
    } else {
      vy = Value.createError(dataWidth);
    }

    // propagate them
    int delay = dataWidth.getWidth() * (3 * Adder.PER_DELAY);
    state.setPort(OUT, vy, delay);
  }
View Full Code Here

 
  /** Computes the next gray value in the sequence after prev. This static
   * method just does some bit twiddling; it doesn't have much to do with
   * Logisim except that it manipulates Value and BitWidth objects. */
  static Value nextGray(Value prev) {
    BitWidth bits = prev.getBitWidth();
    if (!prev.isFullyDefined()) return Value.createError(bits);
    int x = prev.toIntValue();
    int ct = (x >> 16) ^ x; // compute parity of x
    ct = (ct >> 8) ^ ct;
    ct = (ct >> 4) ^ ct;
    ct = (ct >> 2) ^ ct;
    ct = (ct >> 1) ^ ct;
    if ((ct & 1) == 0) { // if parity is even, flip 1's bit
      x = x ^ 1;
    } else { // else flip bit just above last 1
      int y = x ^ (x & (x - 1)); // first compute the last 1
      y = (y << 1) & bits.getMask();
      x = (y == 0 ? 0 : x ^ y);
    }
    return Value.createKnown(bits, x);
  }
View Full Code Here

  /** Draws an indicator that the caret is being selected. Here, we'll draw
   * a red rectangle around the value. */
  @Override
  public void paint(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
    int len = (width.getWidth() + 3) / 4;

    Graphics g = painter.getGraphics();
    g.setColor(Color.RED);
    int wid = 7 * len + 2; // width of caret rectangle
    int ht = 16; // height of caret rectangle
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.