/* ----------------------------------------------------------------P. S. O---
 *  FIRST UPDATE : Dec. 12. 1990 all ok !
 *  LIB Ver      : 1.00
 * --------------------------------------------------------------------------
 * Fuse_su		      : 2178     [54 * 40 others 18]
 * -------------------------------------------------------------------------- */
declaration
  dataunit : bit 
  ;
  functions
    Program
    Read
    Verify
    Blank_Check
    Auto
  ;
  Manufacturers
    SIGNETICS
  ;
  Devices
    PLS173
  ;
		/*  ΥΝΝΝΝΈΥΝΝΝΝΈ        */
  chips =  C0,  /* [³ 1     24 ³] VCC   */
           C1,  /* [³ 2     23 ³] NC4   */
	   C2,  /* [³ 3     12 ³] FS    */
	   C3,  /* [³ 4     21 ³] PV    */
	   C4,  /* [³ 5     20 ³] FN    */
           C5,  /* [³ 6     19 ³] NC3   */
	   C6,  /* [³ 7     18 ³] NC2   */
	   R0,  /* [³ 8     17 ³] NC1   */
	   R1,  /* [³ 9     16 ³] NC0   */
	   R2,  /* [³ 10    15 ³] R5    */
	   R3,  /* [³ 11    14 ³] R4    */
	  GND,  /* [³ 12    13 ³] STROBE*/
		/*  ΤΝΝΝΝΝΝΝΝΝΝΎ        */
	STROBE, R4, R5, NC0, NC1, NC2, NC3, FN, PV, FS, NC4, VCC;
  $v2 = FS;
  $v3 = VCC;
endd

int row[55] = { 0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
               10, 11, 12, 13, 14, 15, 36, 37, 38, 39,
	       40, 41, 42, 43, 34, 35, 32, 33, 30, 31,
	       28, 29, 26, 27, 24, 25, 22, 23, 20, 21,
	       18, 19, 16, 17, 48, 49, 50, 51, 52, 53,
	       54, 55, 56, 57};

int disp_flag = 0;
int index     = 6;
/* -----------------------------------------------------------------------
 * Display processing
 * ----------------------------------------------------------------------- */
int disp(option, p)
int option, p;
{
  if(disp_flag == 1) return(p);
  if(p == 0) {
    if     (option == 'p') @Display 26, index, "Programming ...";    
    else if(option == 'r') @Display 26, index, "Reading ...";      
    else if(option == 'b') @Display 26, index, "Blank checking ...";
    else if(option == 'v') @Display 26, index, "Verifying ...   ";
    else if(option == 's') @Display 26, index, "Securing ...";
  }
  else {   
    if     (option == 'p') @Display 26, index, "Program OK!    ";
    else if(option == 'r') @Display 26, index, "Read OK!   ";
    else if(option == 'b') @Display 26, index, "Blank check OK!   ";
    else if(option == 'v') @Display 26, index, "Verification OK!";
    else if(option == 's') @Display 26, index, "Security OK!";
    index ++;
  }
}
/* -----------------------------------------------------------------------
 * init() ---> inital processing
 * ----------------------------------------------------------------------- */
int init()
{
  @Vout 1,    17.50;	/* NULL */
  @Vout 2,    17.50;    /* Vp   */
  @Vout 3,     8.50;    /* Vccp */
  @Out  GND,  	 @G;
  @Delay 10, @Ms;  

  @Out VCC,      @W;
  @Out NC[0..4], @W;  
  @Out C[0..6],  @W;
  @Out R[0..5],  @W; 
  @Out FS,       @W;
  @Out STROBE,   @W;
  @Out FN,       @Z;
  @Out PV,       @W;

  @Out VCC,      @L;
  @Out NC[0..4], @L;  
  @Out C[0..6],  @L;
  @Out R[0..5],  @L; 
  @Out FS,       @L;
  @Out STROBE,   @H;
  @Out PV,       @L;

  @Delay 1, @Ms;
}
/* -----------------------------------------------------------------------
 * Read data from device
 * Blank check
 * Verify
 * ----------------------------------------------------------------------- */
int verifyf(address, data, option)
int address, data, option;
{
  int	tmp;

  @Display 67, 9, address, @d;

  if     (option == 'r') @Load data;		/* Read data	   */
  else if(option == 'b') {			/* Blank check     */
    if(data & 1 != 0)  @Exit;
  }
  else if(option == 'v') {			/* Verify check    */
    @Store tmp;
    if ((tmp&1) != (data&1)) @Exit;
  }
  else if(option == 'p') {			/* Program verify check    */
    @Store tmp;
    if ((tmp&1) != (data&1)) @Exit;
  }
}
/* -----------------------------------------------------------------------
 * 1 bit(s) data process
 * ----------------------------------------------------------------------- */
int sub(i, j, option, address)
int  i,       					/* Column addressing	   */
     j,       					/* Row addressing	   */
     option,   					/* Read, Program.. or more */
     address;
{
  int pgm_d,					/* Program data     */
      read_d;					/* Read data        */
      
  pgm_d = read_d = 0;     
      
  @Set 0, address;
  @Store pgm_d;
         
  @Out C[0..6], i;
  @Out R[0..5], j;

  @Out VCC, @O; 
  if(option == 'p') {				/* Program bit 	*/
    if(pgm_d == 1) {
      @Out PV,   @H;
      @Out FS,   @O;
      @PinDelay STROBE, @L, @H, 5;
      @Out FS,   @F; 
      @Out PV,   @L;
    }
  }
  @Out STROBE, @L; 
  @In FN, read_d;
  @Out STROBE, @H;
  @Out VCC,    @F;
  verifyf(address, read_d, option);
}
/* -----------------------------------------------------------------------
 * Top program
 * ----------------------------------------------------------------------- */
int top(option)
int option;
{
  int i, j, k;

  disp(option, 0);
  init();

  k = 0;
             
  for(i=0; i<32; i++) {					/* AND, OR array */
    for(j=0; j<54; j++) {
      sub(i, row[j], option, k++);
    }
  }

  for(i=0; i<10; i++) {					/* OE array */
    for(j=0; j<44; j++) {
      sub(i+32, row[j], option, k++);
    }
  }

  for(i=0; i<10; i++) {					/* EXOR array */
    sub(51-i, 58, option, k++);
  }
  disp(option, 1);
}
/* -----------------------------------------------------------------------
 * MAIN Program
 * ----------------------------------------------------------------------- */
int main()
{
  index = 6;

  if     (FUNCTION == Program) {
    top('p');					/* Program device     */
    top('v');					/* Verify device      */
  }
  else if(FUNCTION == Read) {           	/* Read device        */
    top('r');	
    @CheckSumOn;
  }
  else if(FUNCTION == Blank_Check) top('b');	/* Blank check device */
  else if(FUNCTION == Verify)      top('v');	/* Verify device      */
  else if(FUNCTION == Auto) {
    top('b');					/* Blank check device */
    top('p');					/* Program device     */
    top('v');					/* Verify device      */
  }
}
/* ------------------------------- End of program ------------------------ */
 