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

public class left_edge2 extends Logic {
  
  public static CellInterface[] cell_interface = {
    in( "char_in", 4 ),
    out( "src_dist_out", 1 ),
    out( "reset", 1 ),
    out( "char_out", 4 )
  };
 
  public left_edge2(Node parent, Wire char_in, Wire src_dist_out,
		    Wire reset, Wire char_out) {
    super(parent); 

    connect("char_in", char_in);
    connect("char_out", char_out);
    connect("src_dist_out", src_dist_out);
    connect("reset", reset);

    Wire src_null = wire(1, "src_null");

    // the source character is null if all bits of the one_hot encoded character
    // are zero.
    not_o(or(char_in.getWire(0),char_in.getWire(1),char_in.getWire(2),char_in.getWire(3)),src_null);

    // Pass the source character through and assert reset if character is null.
    reg_o(char_in, char_out);
    reg_o(src_null, reset);

    // This initializes the horizontal distance.
    // 1 == greater than the diagonal
    // 0 == less than the diagonal
    vcc_o(src_dist_out);

  }
}
