/*
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 charcomp2 extends Logic {
  
  public static CellInterface[] cell_interface = {
    in( "char_in", 4 ),
    out( "match", 1 ),
    out( "char_out", 4 )
  };
 
  public charcomp2(Node parent, Wire char_in, Wire match,
		   Wire char_out, char target) {
    super(parent); 

    connect("char_in", char_in);
    connect("char_out", char_out);
    connect("match", match);

    // pass character in, to character out.
    reg_o(char_in, char_out);

    /* The source character is encoded in a one_hot scheme,
       with 'a' represented by the lsb, and going up in alphabetical order.
       A match is determined by the target character.  */
    if (target == 'a') {
      buf_o(char_in.getWire(0),match);}
    else if (target == 'c') {
      buf_o(char_in.getWire(1),match);}
    else if (target == 'g') {
      buf_o(char_in.getWire(2),match);}
    else if (target == 't') {
      buf_o(char_in.getWire(3),match);}
    else if (target == 'r') {
      or_o(char_in.getWire(0),char_in.getWire(2),match);}
    else if (target == 'y') {
      or_o(char_in.getWire(1),char_in.getWire(3),match);}
    else if (target == 'n') {
      or_o(char_in.getWire(0),char_in.getWire(1),char_in.getWire(2),char_in.getWire(3),match);}
    else {
      buf_o(gnd(),match);}
    
  }
}
