/* Copyright: (C) 2002 Brigham Young University This program is free software; you can redistribute it and/or modify it under the terms of the Open Source Software License Agreement for JHDL. You should have received a copy of the Open Source Software License for JHDL along with this program. If you have not, download the License Agreement at http://www.jhdl.org/license.html or write to: Brad Hutchings 459 Clyde Bldg Brigham Young University Provo, UT 84602 */ /** TestBench for the NBitAccum design * @author Anthony L. Slade */ import java.awt.Container; import javax.swing.JFrame; import javax.swing.JOptionPane; import byucc.jhdl.apps.Stimulator.Stimulator; import byucc.jhdl.base.HWSystem; import byucc.jhdl.base.Node; import byucc.jhdl.base.ProgrammaticTestBench; import byucc.jhdl.base.TestBench; import byucc.jhdl.base.Wire; import byucc.jhdl.Logic.Logic; public class tbNBitAccum extends Logic implements ProgrammaticTestBench{ public static void main(String[] arguments) { int width = 0; for ( int ai = 0; ai < arguments.length; ++ai ) { try { width = Integer.parseInt(arguments[ai]); break; } catch ( NumberFormatException nfe ) { width = 0; } } { String messageBase = "Enter a width for the accumulator", message = messageBase; while ( width == 0 ) { String widthStr = JOptionPane.showInputDialog(message); try { width = Integer.parseInt(widthStr); } catch ( NumberFormatException nfe ) { message = "Sorry, I couldn't interpret \"" + widthStr + "\" as a number.\n" + messageBase; width = 0; } } } // Build the TestBench and invoke a new visualization tool tbNBitAccum tb = new tbNBitAccum(new HWSystem(), width); tb.createVisualizationTool(); } Stimulator stimulator; NBitAccum design; /** Constructor for the this TestBench */ tbNBitAccum(Node parent, int width) { super(parent); // Create wires and build the design Wire reset, input, output; reset = wire(1,"reset"); input = wire(width,"input"); output = wire(width,"output"); design = new NBitAccum(this, reset, input, output ); // Create Stimulator object to allow the user to easily put values // to the top-level inputs to the circuit. stimulator = new Stimulator(this); stimulator.addWire(reset); stimulator.addWire(input,"2"); } /** The main loop method for ProgrammaticTestBench interface */ public void execute() { getSystem().cycle(1); } /** Create a custom visualization tool just for this design */ JFrame createVisualizationTool() { AccumCVT cvt = new AccumCVT(this); stimulator.registerCLICommands( cvt.getInterp() ); return cvt; } } // end class tbNBitAccum