In this example of a 4-way MUX with a 4-bit datapath we concentrate on the view, showing a customized footprint and pin positioning. The plug-in uses bundled data: it bundles each of the 4 4-bit data path alternatives as a (signed) integer.
package plugins.components.mux; import dlsim.document.DLPlugIn; public class MUX4 extends DLPlugIn { /** * 4-way, 4-bit wide multiplexer * @author rms */ private static final long serialVersionUID = DLFrame.SID; private static int IN = 0, S = 4, OUT = 5; // positions private static int BITWIDTH = 4, SS = 4, SWIDTH = 2; public static PluginInfo info = new PluginInfo("4-way multiplexer using bundled data", "Bitwidth = 4"); public MUX4() { setPrintName("MUX-4"); setInputSize(SS*BITWIDTH+SWIDTH); setOutputSize(BITWIDTH); setInMap(BITWIDTH, BITWIDTH, BITWIDTH, BITWIDTH, SWIDTH); setOutMap(BITWIDTH); setLabels("I0(4)", "I1(4)", "I2(4)", "I3(4)", "S0-S1", "O(4)"); } public void evalState(int source, int val) { int choice = (int)getBundle(S); putBundle(OUT, (int)putBundle(IN+choice)); } }
package plugins.components.mux; import java.awt.Color; import dlsim.document.DLPlugIn; import dlsim.view.util.UserPluginView; public class MUX4View extends UserPluginView { /** * Custom view for MUX4 * @author rms */ private static final Color BGC = new Color(100,100,255); private static final int HT = 70, WD = 170, NAMEX = 55, NAMEY = 40 public MUX4View() { super(); } public MUX4View(DLPlugIn plugin) { super(plugin); } public void setup() { setBGCOL(BGC); setHT(HT); /* height */ setWD(WD); /* width */ setNameX(NAMEX); /* where printname is printed */ setNameY(NAMEY); setPolygon(new int[][]{{30, 140, 140, 30}, {0, 20, 50, 70}}); PinDesc[] leftPins = new PinDesc[]{ new PinDesc(0, 20, 30), new PinDesc(1, 30, 30), new PinDesc(2, 40, 30), new PinDesc(3, 50, 30) }; PinDesc[] rightPins = new PinDesc[]{new PinDesc(5, 30, 30)}; PinDesc[] botPins = new PinDesc[]{new PinDesc(4, 110, 14)}; setLeftPins(leftPins); setRightPins(rightPins); setBotPins(botPins); } }
Run DLSim 3 (using "ant run") and build the circuit shown below using Mux4.
Exercises