#include<stdio.h>
#include<math.h>

#define  stdprn NULL

/* ---------------------------------------------------------------*/
#define RI2P "RI2P1.bin"
/* ---------------------------------------------------------------*/

	unsigned long int samp;
	int a,b,c,d,Adr,r,i,p;
	FILE *NEW;
	int r1, i1, p1,qp;
	char ir,rp ;

void main()
{
  fprintf(stdout,"    RI 2 Power LOOK-UP combiner      \n") ;
  fprintf(stdout,"It takes in  R and I in 2's comp      \n") ;
  fprintf(stdout,"and produces a RI to Pwr Lookup contents\n") ;
  fprintf(stdout," This PROM is for checking the GAC PA o/p \n") ;
  fprintf(stdout," Output file name : %s\n\n",RI2P);

  NEW = fopen(RI2P, "wb");

  samp=1;
      for(b=0;b<=31;b++)        /*   Imaginary part, */
	for(a=0;a<=31;a++)      /*  and Real parts. */
	{
		 if((a&0x10)==0x10)        /* 1111 1111 111x xxxx */
		     r1 = -(~(a|0xffe0)+1);
		 else  r1 = a;

		 if((b&0x10)==0x10)
		     i1 = -(~(b|0xffe0)+1);
		 else  i1 = b;

		 p1 = r1*r1+i1*i1 ;
		 qp = (p1+4)>>3;

		 printf("r=%3d  i=%3d  p=%3d  qp=%d\n",r1,i1,p1,qp);

		fwrite(&qp,1,1,NEW);

		/* ------------------below codes are just for monitoring */
			 if(fmod(samp,32)==0)
			    printf("Finished combining %6ld samples\n",samp);
			 samp++;
	  }
  printf("\nSaved all values\nExiting\n\n");
  fcloseall();
} /* End of Program          */








