/*  file name:ALL16A.c  Ver:1  - Dated : 10 Jan '96   */					
/* *************************************************  */
/*  U16 and U17   CY 27H010             DIAGNOSTICS   */
/*  For the 4 input card  			      */
/* *************************************************  */

/* This program generates 16 lookup tables for U16 &17 */
/* the first table has 0 to 63,0-63,0-63,...           */
/* the 2nd tabel starts with 1-63,0-63,...	       */
/* the 3rd one    "     with 2-63,0-63,...             */
/* and so on */

#include "gac.h"
#define FileName1 "ALL16U16.BIN"
#define FileName2 "ALL16U17.BIN"

main()
{	unsigned int data1, data2 ;
	unsigned int pwr, re, img, d ;
	int i,j ;
	FILE *out1, *out2 ;

   clrscr() ;	
   out1 = fopen(FileName1,"wb");    /*  */
   out2 = fopen(FileName2,"wb");    /*  */

   for(j=0;j<=15;j++)
   {  for(i=0;i<=4095;i++)
      {   pwr = (i+j) & 0x3f ;       /* take the LS 6 bits  -> Power */
	  re = (pwr & 0x001f) ;  /* take  only LS 5 bits -> Real    */
	  re = (re << 6) & 0x07c0 ; /* Bring to ROM's Real field position */ 
	  img = (pwr & 0x001f) ;  /* take  only LS 5 bits -> Iamaginary */
	  img = (img << 11) & 0xf800 ; /* Bring to ROM's Imaginary field position */ 
	  d = img | re | pwr ;
	  
	  data1 = d &0xff ;
	  data2 = ( d >> 8 ) &0xff ;
	  printf("%2x %2x   ",data1, data2 ) ;   
	  fwrite(&data1,1,1,out1) ;   /* write U16 data */
	  fwrite(&data2,1,1,out2) ;   /* write U17 data */
      }
      printf("\n End of table  %d \n\n",j) ;
    } /* end for j */
   fcloseall() ;

}
	 