Code:
/*-------------------------------------------------------------------+
| |
| +------------------------------+ |
| | Logic Simulator | |
| +------------------------------+ |
| version 1.0 |
| Sept. 19 1989 |
| by Kyuchull Kim |
| |
+-------------------------------------------------------------------*/
#include "main.h"
extern MakeNetwork();
extern Get_level();
extern Init_Network();
extern Order_PO();
extern Gettest();
extern Simulate();
extern gettest();
PrintInput();
PrintOutput();
PrintGateValue();
extern Get_Transition();
extern Sort_Transition();
/*******************************************************************/
main(argc,argv)
int argc;
char *argv[]; /* file name of network description */
{
int count = 0;
char DATAname[50],NETname[50];
// struct tms buf1, buf2;
accumulate=0; /* default is not to accumulate the vectors */
included=1;
//readcommandline(argc,argv);
printf("Net Filename: ");
scanf("%s",NETname);
strcpy(DATAname,NETname);
DATAname[0]='c';
strcat(NETname,".nf");
strcat(DATAname,".tc");
// fnet=fopen(NETname,"r");
// fvector=fopen(DATAname,"r");
// fpo=fopen("out","w");
if ((fnet=fopen(NETname,"r")) ==NULL)
fprintf(fpo,"ERROR: cannot open netfile \n");
if ((fvector=fopen(DATAname,"r")) == NULL)
fprintf(fpo,"ERROR: cannot open vector file \n");
if ((fpo=fopen("out","w")) ==NULL)
fprintf(fpo,"ERROR: cannot open output file \n");
fprintf(fpo,"******** Input file : %s ********* \n",DATAname);
accumulate = 0;
MakeNetwork(); /* read in network description from fnet & form a network */
// PrintNet();
Get_level();
// printpolist(); */
Order_PO();
// /* printpolist(); */
Init_Network();
while (gettest() == OK){
Simulate(count);
count++;
PrintInput(count);
PrintOutput(count);
if(!accumulate)
// Reset_Network();
Init_Network(); //Added AlShaibi */
}
TotalTestVec = count;
PrintGateValue();
} /* end of main */
/*-----------------------------------------------------------------*/
/* purpose: print the value of PI */
/*-----------------------------------------------------------------*/
PrintInput(count)
int count;
{
int i;
ListNode *ptr;
// fprintf(fpo,"IV%4d:",count);
ptr = PI_List;
for(i=0; ptr != NULL; i++) {
//if (i > 10 ){ fprintf(fpo,"\n "); i=0; }
// fprintf(fpo,"%d/%c ",GATENAME(ptr->gateno),(GATEVALUE(ptr->gateno) == X) ?
// 'X' : (GATEVALUE(ptr->gateno)&1) + '0');
ptr = ptr->next;
}
//fprintf(fpo,"\n");
}
/*-----------------------------------------------------------------*/
/* purpose: print the value of PO */
/*-----------------------------------------------------------------*/
PrintOutput(count)
int count;
{
ListNode *ptr;
int i;
ptr = PO_List;
//fprintf(fpo,"OV%4d:",count);
for(i = 0; ptr != NULL; i++){
// if (i > 10 ){ fprintf(fpo,"\n "); i=0; }
// fprintf(fpo," %d/%c",GATENAME(ptr->gateno),(GATEVALUE(ptr->gateno) == X)?
// 'X':(GATEVALUE(ptr->gateno)&1) + '0');
ptr = ptr->next;
}
//fprintf(fpo,"\n");
return 0;
}
/*-----------------------------------------------------------------*/
/* purpose: print the value of PO */
/*-----------------------------------------------------------------*/
PrintGateValue(){
int i,j,gp,k;
//fprintf(fpo,"***** NodeValues **************\n");
for( k = 0; k<TotalGate; k++){
fprintf(fpo,"%s ",Gate[k].name);}
fprintf(fpo,"\n");
for(i = 0; i<TotalTestVec; i++){
//fprintf(fpo,"TestV %d: ",i);
for(j = 0; j<TotalGate; j++){
if(Gate[j].value[i]== X)
fprintf(fpo,"%c",'X');
else {
gp = GATEnode[j];
//fprintf(fpo," %s",Gate[j].name);
//fprintf(fpo,"\n");
fprintf(fpo,"%d",Gate[j].value[i]&1 + '0');
}
}
fprintf(fpo,"\n");
}
fprintf(fpo,"\n");
return 0;
}