/*
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


*/


import byucc.jhdl.base.CellInterface;
import byucc.jhdl.base.Node;
import byucc.jhdl.base.Wire;
 
import byucc.jhdl.Logic.Logic;

/** Counter counts up if up_down is a 1, down if up_down is a 0.
*/
public class upDownCounter extends Logic {
  public static CellInterface[] cell_interface = {
    in( "load", 1 ),
    in( "load_value", "wid1" ),
    in( "up_down", 1 ),
    in( "clken", 1 ),
    out( "count", "wid1" ),
    param( "wid1", INTEGER )
  };
  
  public upDownCounter(Node parent, Wire load, Wire load_value,
		       Wire up_down, Wire clken, Wire count) {

    super(parent);

    int width = count.getWidth();

    bind( "wid1", width);

    connect("load", load);
    connect("load_value", load_value);
    connect("up_down", up_down);
    connect("clken",clken);
    connect("count", count);

    regce_o(mux(addsub(count, constant(width, 1), up_down), load_value,load), clken, count);
  }
}
