/* ADD331-A.C -->  This program generates the 8IP Card 331-Adder EPROM contents
		   CY7C291 (U21, U22).  The inputs are two 3-bit numbers and a
		   carry bit.  The sum produced is a 4-bit number.


		______        CY7C291
	  Cin--|      |		
	A(3)---| Add  |- Cin+A+B (4-bits)
	B(3)---|      |
		------

				   16th Apr. 1997   JR  GK */


#include <stdio.h>
#include <conio.h>

main()
{
	int i, a, b, c;
	unsigned char sum;
	FILE *f1, *f2;

	f1 = fopen("ADD331-A.TXT", "wt");
	f2 = fopen("ADD331-A.BIN", "wb");
	clrscr();

	fprintf(f1, "ADD331-A.C generated this 8IP Card 331-Adder EPROM contents \n");
	fprintf(f1, "viz., CY7C291 (U21, U22).The inputs are two 3-bit numbers and\n");
	fprintf(f1, "a carry bit.  The sum produced is a 4-bit number.    16th Apr.1997   JR  GK\n\n");


	fprintf(f1,"  i  -  a +   b + c =   sum\n\n");

	for(i=0; i<128; i++)
	{	
		a = (i>>1) & 0x7;
		b = (i>>4) & 0x7;
		c = i & 0x1;

		sum = (a + b + c) & 0xf;
		fprintf(f1,"%3x - %3x + %3x + %1x = %4x \n", i, a, b, c, sum);
		fwrite(&sum, sizeof(sum), 1, f2);
	}
	fcloseall();
}
