import  java.io.IOException;

import  com.xilinx.JBits.Virtex.JBits;
import  com.xilinx.JBits.Virtex.Devices;
import  com.xilinx.JBits.Virtex.Util;
import  com.xilinx.JBits.Virtex.ConfigurationException;
import com.xilinx.JBits.Virtex.Bits.*;
import com.xilinx.JBits.Virtex.Expr;
import  com.xilinx.JBits.Virtex.RTPCore.Tags;
import  com.xilinx.JBits.Virtex.RTPCore.DAfilter;

import  com.xilinx.JBits.Virtex.RTPCore.*;


/** 
**  This class is used to demonstrate the JBits library
**  capability.  It reads in a bitstream, instantiates some
**  JBits library objects and writes the modified
**  bitstream.
**
**  <p>
**
**  Copyright (c)  2000 Jamil Khatib
**
**  <p>
**
**  @version    1.0  June 12, 2000
**  @author     Jamil Khatib
**/


public class TestDA  {


    /**
     **  This is the main program.
     **
     */

    public static void
        main(String  args[]) {
        String  usage = "Usage:  LibTest -<device> <infile.bit> <outfile.bit>.  Exiting.";
  
        int       size;
        int       row;
        int       col;
        int       clbRows;
        int       clbColumns;

        int       deviceCount;
        int       deviceType = Devices.UNKNOWN_DEVICE;
        String    infileName = "";
        String    outfileName = "";
        String    deviceName = "";
        JBits     jBits;

        DAfilter filter = null;

        int taps;
   
        int constants[];
   
   
   

        /*
        **  Parse command line parameters
        */

        if (args.length == 3) {
            deviceName = args[0];
            infileName = args[1];
            outfileName = args[2];
        } else {
            System.out.println(usage);
            System.exit(-1);
        }  /* end if() */

        /* Get rid of "-" in device name flag */
        if (deviceName.startsWith("-") == true)
            deviceName = deviceName.substring(1);

        /* Get the device type */
        deviceType = Devices.getDeviceType(deviceName);
        if (deviceType == Devices.UNKNOWN_DEVICE) {
            System.out.println("Did not recognize device type.  Exiting");
            System.exit(-2);
        }

        /* Be sure the device is supported */
        if (Devices.isSupported(deviceType) == false) {
            System.out.println("Unsupported device type.  Exiting");
            System.exit(-3);
        }

        System.out.println("Device:  " + Devices.getDeviceName(deviceType));

        /* Get the device model */
        jBits = new JBits(deviceType);

        /* Read in the bit file */
        System.out.println("Reading in "+infileName+".");
        System.out.println("");

        try {
            jBits.read(infileName);
        } catch (Exception e) {
            System.out.println("Could not read in bitstream from file " +
                               infileName + ".  Exiting.");
            System.exit(-4);
        }  /* end catch() */

        System.out.println("Success reading from bitstream file "+infileName+".");
  
        /*
        **  Construct some objects and write them to the bitstream
        */

        try {

            size = 8;
            taps = 4;
            constants = new int[taps];
            
            constants[0] = 1;
            constants[1] = 0;
            constants[2] = 0;
            constants[3] = 1;
/*   constants[4] = 0;
   constants[5] = 0;
   constants[6] = 0;
   constants[7] = 1;
*/
            filter    = new DAfilter(size, taps,constants) ; /*Construct*/
            filter.set(jBits, 7,0); /*set*/

     

        } catch (Exception ce) {

            System.out.println(ce.toString());
            System.out.println("Exiting.");
            System.exit(-5);

        }  /* end catch() */

/*Testing the core*/
        filter.test_parm();
        

        /* Write out the bitstream file */
        System.out.println("Writing file " + outfileName + ".");

        try {
            jBits.write(outfileName);
        } catch (IOException  ioe) {
            System.out.println("Error writing file " + outfileName + ".  Exiting.");
            System.exit(-5);
        }  /* end catch() */

        System.out.println("Success writing to " + outfileName + ".");
   
        System.out.println("Exiting.");

    }  /* end main() */



}  /* end class TestDA */


