Package com.cburch.logisim.data

Examples of com.cburch.logisim.data.BitWidth


  }

  @Override
  public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
    int outputs = 1 << select.getWidth();
    Bounds bds;
    if (outputs == 2) {
      bds = Bounds.create(0, -20, 30, 40);
    } else {
      bds = Bounds.create(0, -(outputs / 2) * 10 - 10,
View Full Code Here


  }

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

  }

  @Override
  public void propagate(InstanceState state) {
    MemState myState = getState(state);
    BitWidth dataBits = state.getAttributeValue(DATA_ATTR);

    Value addrValue = state.getPort(ADDR);
    boolean chipSelect = state.getPort(CS) != Value.FALSE;
   
    if (!chipSelect) {
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    // get attributes
    BitWidth data = state.getAttributeValue(StdAttr.WIDTH);
    BitWidth select = state.getAttributeValue(Plexers.ATTR_SELECT);
    Boolean threeState = state.getAttributeValue(Plexers.ATTR_TRISTATE);
    boolean enable = state.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    Value en = enable ? state.getPort(outputs + 1) : Value.TRUE;

    // determine output values
    Value others; // the default output
    if (threeState.booleanValue()) {
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.reverse(), 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 outputs = 1 << select.getWidth();

    // draw select and enable inputs
    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 ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) { // draw select wire
      Location sel = painter.getInstance().getPortLocation(outputs);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs).getColor());
      }
      g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
    }
    if (enable) {
      Location en = painter.getInstance().getPortLocation(outputs + 1);
      if (painter.getShowState()) {
        g.setColor(painter.getPort(outputs + 1).getColor());
      }
      int len = outputs == 2 ? 6 : 4;
      g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
    }
    GraphicsUtil.switchToWidth(g, 1);
   
    // draw a circle indicating where the select input is located
    Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));

    // draw "0" next to first input
    int x0;
    int y0;
    int halign;
    if (facing == Direction.WEST) {
      x0 = 3;
      y0 = 15;
      halign = GraphicsUtil.H_LEFT;
    } else if (facing == Direction.NORTH) {
      x0 = 10;
      y0 = 15;
      halign = GraphicsUtil.H_CENTER;
    } else if (facing == Direction.SOUTH) {
      x0 = 10;
      y0 = bds.getHeight() - 3;
      halign = GraphicsUtil.H_CENTER;
    } else {
      x0 = bds.getWidth() - 3;
      y0 = 15;
      halign = GraphicsUtil.H_RIGHT;
    }
    g.setColor(Color.GRAY);
    GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0,
        halign, GraphicsUtil.V_BASELINE);

    // draw trapezoid, "DMX" label, and ports
    g.setColor(Color.BLACK);
    Plexers.drawTrapezoid(g, bds, facing.reverse(), select.getWidth() == 1 ? 10 : 20);
    GraphicsUtil.drawCenteredText(g, "DMX",
        bds.getX() + bds.getWidth() / 2,
        bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
  }
View Full Code Here

    return vs.length;
  }
 
  public void setDimensions(BitWidth newWidth, int newLength) {
    Value[] v = vs;
    BitWidth oldWidth = width;
    int oldW = oldWidth.getWidth();
    int newW = newWidth.getWidth();
    if (v.length != newLength) {
      Value[] newV = new Value[newLength];
      int j = vsPos;
      int copy = Math.min(newLength, v.length);
View Full Code Here

  }

  @Override
  public void propagate(InstanceState state) {
    Value control = state.getPort(2);
    BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
    if (control == Value.TRUE) {
      Value in = state.getPort(1);
      state.setPort(0, isInverter ? in.not() : in, GateAttributes.DELAY);
    } else if (control == Value.ERROR || control == Value.UNKNOWN) {
      state.setPort(0, Value.createError(width), GateAttributes.DELAY);
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();
    int offs = -5 * inputs;
    int len = 10 * inputs + 10;
    if (dir == Direction.NORTH) {
      return Bounds.create(offs,   0, len, 40);
    } else if (dir == Direction.SOUTH) {
View Full Code Here

    }
  }

  private void updatePorts(Instance instance) {
    Object dir = instance.getAttributeValue(StdAttr.FACING);
    BitWidth select = instance.getAttributeValue(Plexers.ATTR_SELECT);
    int n = 1 << select.getWidth();
    Port[] ps = new Port[n + 4];
    if (dir == Direction.NORTH || dir == Direction.SOUTH) {
      int x = -5 * n + 10;
      int y = dir == Direction.NORTH ? 40 : -40;
      for (int i = 0; i < n; i++) {
        ps[i] = new Port(x + 10 * i, y, Port.INPUT, 1);
      }
      ps[n + OUT] = new Port(0, 0, Port.OUTPUT, select.getWidth());
      ps[n + EN_IN] = new Port(x + 10 * n, y / 2, Port.INPUT, 1);
      ps[n + EN_OUT] = new Port(x - 10, y / 2, Port.OUTPUT, 1);
      ps[n + GS] = new Port(10, 0, Port.OUTPUT, 1);
    } else {
      int x = dir == Direction.EAST ? -40 : 40;
      int y = -5 * n + 10;
      for (int i = 0; i < n; i++) {
        ps[i] = new Port(x, y + 10 * i, Port.INPUT, 1);
      }
      ps[n + OUT] = new Port(0, 0, Port.OUTPUT, select.getWidth());
      ps[n + EN_IN] = new Port(x / 2, y + 10 * n, Port.INPUT, 1);
      ps[n + EN_OUT] = new Port(x / 2, y - 10, Port.OUTPUT, 1);
      ps[n + GS] = new Port(0, 10, Port.OUTPUT, 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.