Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


  }

  @Override
  public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value c_in = state.getPort(C_IN);
    Value[] outs = Multiplier.computeProduct(dataWidth, a, b, c_in);

    // propagate them
    int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT,   outs[0], delay);
    state.setPort(C_OUT, outs[1], delay);
  }
View Full Code Here


    public void attributeListChanged(AttributeEvent e) { }

    public void attributeValueChanged(AttributeEvent e) {
      AttributeSet attrs = e.getSource();
      BitWidth addrBits = attrs.getValue(Mem.ADDR_ATTR);
      BitWidth dataBits = attrs.getValue(Mem.DATA_ATTR);
      getContents().setDimensions(addrBits.getWidth(), dataBits.getWidth());
    }
View Full Code Here

  }
 
  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction dir = attrs.getValue(StdAttr.FACING);
    BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
    int inputs = 1 << select.getWidth();
    if (inputs == 2) {
      return Bounds.create(-30, -20, 30, 40).rotate(Direction.EAST, dir, 0, 0);
    } else {
      int offs = -(inputs / 2) * 10 - 10;
      int length = inputs * 10 + 20;
View Full Code Here

  }

  private void updatePorts(Instance instance) {
    Direction dir = 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 selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int inputs = 1 << select.getWidth();
    Port[] ps = new Port[inputs + (enable ? 3 : 2)];
    Location sel;
    if (inputs == 2) {
      Location end0;
      Location end1;
      if (dir == Direction.WEST) {
        end0 = Location.create(30, -10);
        end1 = Location.create(3010);
        sel = Location.create(20, selMult * 20);
      } else if (dir == Direction.NORTH) {
        end0 = Location.create(-10, 30);
        end1 = Location.create( 10, 30);
        sel = Location.create(selMult * -2020);
      } else if (dir == 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(-3010);
        sel = Location.create(-20, selMult * 20);
      }
      ps[0] = new Port(end0.getX(), end0.getY(), Port.INPUT,  data.getWidth());
      ps[1] = new Port(end1.getX(), end1.getY(), Port.INPUT,  data.getWidth());
    } else {
      int dx = -(inputs / 2) * 10;
      int ddx = 10;
      int dy = -(inputs / 2) * 10;
      int ddy = 10;
      if (dir == Direction.WEST) {
        dx = 40; ddx = 0;
        sel = Location.create(20, selMult * (dy + 10 * inputs));
      } else if (dir == Direction.NORTH) {
        dy = 40; ddy = 0;
        sel = Location.create(selMult * dx, 20);
      } else if (dir == Direction.SOUTH) {
        dy = -40; ddy = 0;
        sel = Location.create(selMult * dx, -20);
      } else {
        dx = -40; ddx = 0;
        sel = Location.create(-20, selMult * (dy + 10 * inputs));
      }
      for (int i = 0; i < inputs; i++) {
        ps[i] = new Port(dx, dy, Port.INPUT, data.getWidth());
        dx += ddx;
        dy += ddy;
      }
    }
    Location en = sel.translate(dir, 10);
    ps[inputs] = new Port(sel.getX(), sel.getY(), Port.INPUT, select.getWidth());
    if (enable) {
      ps[inputs + 1] = new Port(en.getX(), en.getY(), Port.INPUT, BitWidth.ONE);
    }
    ps[ps.length - 1] = new Port(0, 0, Port.OUTPUT, data.getWidth());

View Full Code Here

    instance.setPorts(ps);
  }

  @Override
  public void propagate(InstanceState state) {
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int inputs = 1 << select.getWidth();
    Value en = enable ? state.getPort(inputs + 1) : Value.TRUE;
    Value out;
    if (en == Value.FALSE) {
      Object opt = state.getAttributeValue(Plexers.ATTR_DISABLED);
      Value base = opt == Plexers.DISABLED_ZERO ? Value.FALSE : Value.UNKNOWN;
View Full Code Here

  }
 
  @Override
  public void paintGhost(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    Plexers.drawTrapezoid(painter.getGraphics(), painter.getBounds(),
        facing, select.getWidth() == 1 ? 10 : 20);
  }
View Full Code Here

  @Override
  public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int inputs = 1 << select.getWidth();
   
    // draw stubs for select/enable inputs that aren't on instance boundary
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing != Direction.NORTH && facing != Direction.SOUTH;
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? 0 : -selMult;
    int dy = vertical ? selMult : 0;
    if (inputs == 2) { // draw select wire
      Location pt = painter.getInstance().getPortLocation(inputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(inputs).getColor());
      }
      g.drawLine(pt.getX() - 2 * dx, pt.getY() - 2 * dy,
          pt.getX(), pt.getY());
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(inputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(inputs + 1).getColor());
      }
      int len = inputs == 2 ? 6 : 4;
      g.drawLine(en.getX() - len * dx, en.getY() - len * dy,
          en.getX(), en.getY());
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(inputs));
   
    // draw a 0 indicating where the numbering starts for inputs
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = bds.getX() + bds.getWidth() - 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_RIGHT;
    } else if (facing == Direction.NORTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + bds.getHeight() - 2;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = bds.getX() + 10;
      y0 = bds.getY() + 12;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getX() + 3;
      y0 = bds.getY() + 15;
      halign = GraphicsUtil.H_LEFT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", x0, y0, halign, GraphicsUtil.V_BASELINE);
   
    // draw the trapezoid, "MUX" string, the individual ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing, select.getWidth() == 1 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "MUX",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value c_in = state.getPort(C_IN);
    Value[] outs = Adder.computeSum(dataWidth, a, b, c_in);

    // propagate them
    int delay = (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT,   outs[0], delay);
    state.setPort(C_OUT, outs[1], delay);
  }
View Full Code Here

    setInstancePoker(Poker.class);
  }

  @Override
  public void propagate(InstanceState state) {
    BitWidth bits = state.getAttributeValue(ATTR_WIDTH);
    int dx;
    int dy;
    State s = (State) state.getData();
    if (s == null) { dx = 0; dy = 0; }
    else { dx = s.xPos; dy = s.yPos; }

    int steps = (1 << bits.getWidth()) - 1;
    dx = (dx + 14) * steps / 29 + 1;
    dy = (dy + 14) * steps / 29 + 1;
    if (bits.getWidth() > 4) {
      if (dx >= steps / 2) dx++;
      if (dy >= steps / 2) dy++;
    }
    state.setPort(0, Value.createKnown(bits, dx), 1);
    state.setPort(1, Value.createKnown(bits, dy), 1);
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    // get attributes
    BitWidth dataWidth = state.getAttributeValue(StdAttr.WIDTH);

    // compute outputs
    Value a = state.getPort(IN0);
    Value b = state.getPort(IN1);
    Value upper = state.getPort(UPPER);
    Value[] outs = Divider.computeResult(dataWidth, a, b, upper);

    // propagate them
    int delay = dataWidth.getWidth() * (dataWidth.getWidth() + 2) * PER_DELAY;
    state.setPort(OUT, outs[0], delay);
    state.setPort(REM, outs[1], delay);
  }
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.