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

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

/* vsram.c */
#include "vikst.h"
typedef struct cnode { INT16 bit[8];
		       INT16 unum; } err;
static err chip[2];
static INT16 a;
sram()
{ INT16 k;
  UINT16 addr,bits;
  UINT16 finished,j;
#ifdef BSD
  extern FILE *out,*spool;
	extern dumpspool();
  extern int v_control;
#endif
  extern UINT16 zero;

  load("sram.vkt");
  chip[0].unum = 31;  chip[1].unum = 51;
  for (a=0; a<8; a++) { chip[0].bit[a] = 0; chip[1].bit[a] = 0; }
  finished = false;
  a=false;
  while( finished == false)
     { 
	delay(BUSWAIT);
	if (look(&addr,&bits,&k))
/*  if(1)	/* DEBUG */
#ifndef NOTIMEOUT
		abortb("Time out in SRAM\n");
#else
		{
		p1d("\007Time out in SRAM -- continuing\n");
		p2d("look returned %x\n",addr);
		dumptime();
		return(0);
		}
#endif
       switch(addr)
	  { case vikdone: finished=true; break;
	    case chkpt:   VIKCONT; break;   /* tell viking to continue */
	    default:	  ramerr(bits);  VIKCONT; break;
	  }
     }
/* DEBUG   a=1; */
  if (a == false) return(false);
  p3d("%4s\n%7s"," ","chip ->");
  p3d("%18s%2d","U",chip[0].unum);
  p3d("%18s%2d","U",chip[1].unum);
  p1d("\n");
  for (k=0; k<=7; k++)
      { p3d("%-4s%-3d","bit",k);
	p3d("%20d%20d",chip[0].bit[k],chip[1].bit[k]);
	p1d("\n");
      }
  return(a);
}

ramerr(bits)
UINT16 bits;
{ UINT16 b;
  a = true;
if (bits &     1) chip[0].bit[0] += 1;
if (bits &     2) chip[0].bit[1] += 1;
if (bits &     4) chip[0].bit[2] += 1;
if (bits &     8) chip[0].bit[3] += 1;
if (bits &    16) chip[0].bit[4] += 1;
if (bits &    32) chip[0].bit[5] += 1;
if (bits &    64) chip[0].bit[6] += 1;
if (bits &   128) chip[0].bit[7] += 1;
if (bits &   256) chip[1].bit[0] += 1;
if (bits &   512) chip[1].bit[1] += 1;
if (bits &  1024) chip[1].bit[2] += 1;
if (bits &  2048) chip[1].bit[3] += 1;
if (bits &  4096) chip[1].bit[4] += 1;
if (bits &  8192) chip[1].bit[5] += 1;
if (bits & 16384) chip[1].bit[6] += 1;
if (bits & 32768) chip[1].bit[7] += 1;
}
