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

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

/* vikmem.c */
#include "vikst.h"
typedef struct cnode { UINT16  lbit[4]; /* unsigned added for BSD */
		       UINT16  hbit[4];
		       UINT16  unum;
		     } chiperr, *chipptr;
chipptr  errloc[4][2];
static INT16 tot;

#ifdef BSD
  extern FILE *out,*spool;
	extern int v_control;
#endif

vikmem()
{ UINT16 segment,length;
  chiperr chip[8];
  extern UINT16 zero;
  extern chipptr errloc[4][2];
  INT16 i,j,k,errs;
  char c;
  char *a,*b;
  tot = 0;
  errs = false;

  chip[0].unum = 39;  chip[1].unum = 29;  chip[2].unum = 58; chip[3].unum = 47;
  chip[4].unum = 38;  chip[5].unum = 28;  chip[6].unum = 57; chip[7].unum = 46;
  for ( i = 0; i <= 3; i++)
      { chip[0].lbit[i] = 0;   chip[1].hbit[i] = 0;
	chip[2].lbit[i] = 0;   chip[3].hbit[i] = 0;
	chip[4].lbit[i] = 0;   chip[5].hbit[i] = 0;
	chip[6].lbit[i] = 0;   chip[7].hbit[i] = 0;
      }
  errloc[0][0] = &(chip[0]);	errloc[0][1] = &(chip[1]);
  errloc[1][0] = &(chip[2]);	errloc[1][1] = &(chip[3]);
  errloc[2][0] = &(chip[4]);	errloc[2][1] = &(chip[5]);
  errloc[3][0] = &(chip[6]);	errloc[3][1] = &(chip[7]);

  segment = 0;
  length  = 0x4000;
  vikstop;
  memtest(segment,length);
  for (k=0; k<=3; k++)
	for (i=0; i<=7; i+=2)
	    { tot += (INT16) chip[i].lbit[k];
	      tot += (INT16) chip[i+1].hbit[k];
	    }
  if (tot != 0)
     { errs = true;
       p3d("%4s\n%7s"," ","chip ->");
       for (i=0; i<=7; i++) p3d("%6s%2d","U",chip[i].unum);
       p1d("\n");
       for (k=0; k<=3; k++)
	   { p3d("%-4s%-3d","bit",k);
	     for (i=0; i<=7; i+=2)
		 p3d("%8d%8d",chip[i].lbit[k],chip[i+1].hbit[k]);
	     p1d("\n");
	   }
     }

  chip[0].unum = 31;  chip[1].unum = 51;
  errloc[0][0] = &(chip[0]);  errloc[0][1] = &(chip[0]);
  errloc[1][0] = &(chip[1]);  errloc[1][1] = &(chip[1]);
  errloc[2][0] = &(chip[0]);  errloc[2][1] = &(chip[0]);
  errloc[3][0] = &(chip[1]);  errloc[3][1] = &(chip[1]);
  for ( i = 0; i <= 3; i++)
      { chip[0].lbit[i] = 0;   chip[0].hbit[i] = 0;
	chip[1].lbit[i] = 0;   chip[1].hbit[i] = 0;
      }
  vikstop;
#ifndef BSD
  zero = 0x88d3;
#else
  zero = 0xd388;
#endif
  vwrite(&zero,1,0);	/* this is a viking microcode program */
  zero = 0;		/* that is basically <<0: goto 0>>    */
  vwrite(&zero,1,2);	/* it looks like:  D3880000	      */

  segment = 0x4000;
  length  = 0x1000;
  memtest(segment,length);
  tot = 0;
  for (k=0; k<=3; k++) tot += (INT16) (chip[0].lbit[k] + chip[1].lbit[k]);
  for (k=4; k<=7; k++) tot += (INT16) (chip[0].hbit[k-4] + chip[1].hbit[k-4]);
  if (tot != 0)
     { errs = true;
       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<=3; k++)
	   { p3d("%-4s%-3d","bit",k);
	     p3d("%20d%20d",chip[0].lbit[k],chip[1].lbit[k]);
	     p1d("\n");
	   }
       for (k=4; k<=7; k++)
	   { p3d("%-4s%-3d","bit",k);
	     p3d("%20d%20d",chip[0].hbit[k-4],chip[1].hbit[k-4]);
	     p1d("\n");
	   }
     }
  if (errs) return(true);
      else  return(false);
}
