/*
 * 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1986
 * LICENSED MATERIALS - PROPERTY OF IBM
 * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
 */
/* $Header:vbufn.c 12.0$ */
/* $ACIS:vbufn.c 12.0$ */
/* $Source: /ibm/acis/usr/src/ibm/aedtest/RCS/vbufn.c,v $ */

#ifndef lint
static char *rcsid = "$Header:vbufn.c 12.0$";
#endif

/* vbufn.c */
#include "vikst.h"
typedef struct cnode { INT16 bit[8];
		       INT16 unum; } err;
static err chip[8];
static INT16 qz,stat;
#ifdef BSD
  extern FILE *out,*spool;
	extern dumpspool();
	extern int v_control;
#endif

bufn()
{ INT16 a,i,k;
  INT16 xx;
  extern UINT16 zero;
  UINT16 type,bits;
  UINT16 finished,j;

  load("bufn.vkt");
  chip[0].unum = 20;  chip[1].unum = 23;
  chip[2].unum =  8;  chip[3].unum = 11;
  chip[4].unum = 32;  chip[5].unum = 40;
  chip[6].unum = 49;  chip[7].unum = 50;
  for (a=0; a<8; a++)
      for (k=0; k<8; k++) chip[k].bit[a] = 0;
  finished = false;
  stat = false;
  qz = 0;
  while( finished == false)
     { if (look(&type,&bits,&k)) 
#ifndef NOTIMEOUT
		abortb("Time out in 29118 test.\n");
#else
		{
		p1d("\007Time out in 29118 test -- continuing.\n");
		p2d("look returned %x\n",type);
		dumptime();
		return(0);
		}
#endif
       switch(type)
	  { case vikdone: finished=true; break;
	    case chkpt:   VIKCONT; break;
	    default:	  bnerr(type,bits);
			  VIKCONT;
			  break;
	  }
     }
  if (stat == false) return(stat);
  p3d("\n%4s\n%7s"," ","chip ->");
  for (k=0; k<8; k++)
      p3d("%6s%2d","U",chip[k].unum);
  p1d("\n");
  for (k=0; k<8; k++)
      { p3d("%-4s%-3d","bit",k);
	for(i=0; i<8; i++) p2d("%8d",chip[i].bit[k]);
	p1d("\n");
      }
  return(stat);
}

bnerr(buf,bits)
UINT16 buf,bits;
{ UINT16 b;
  INT16 x;
  stat = true;
  x = 2*(buf%4);
  if (bits &	 1) chip[x].bit[0] += 1;
  if (bits &	 2) chip[x].bit[1] += 1;
  if (bits &	 4) chip[x].bit[2] += 1;
  if (bits &	 8) chip[x].bit[3] += 1;
  if (bits &	16) chip[x].bit[4] += 1;
  if (bits &	32) chip[x].bit[5] += 1;
  if (bits &	64) chip[x].bit[6] += 1;
  if (bits &   128) chip[x].bit[7] += 1;
  if (bits &   256) chip[x+1].bit[0] += 1;
  if (bits &   512) chip[x+1].bit[1] += 1;
  if (bits &  1024) chip[x+1].bit[2] += 1;
  if (bits &  2048) chip[x+1].bit[3] += 1;
  if (bits &  4096) chip[x+1].bit[4] += 1;
  if (bits &  8192) chip[x+1].bit[5] += 1;
  if (bits & 16384) chip[x+1].bit[6] += 1;
  if (bits & 32768) chip[x+1].bit[7] += 1;
  if ((++qz%4096) == 0) { p1m("."); qz=0; }
}
