/* ----------------------------------------------------------------P. S. O---
 *  FIRST UPDATE : 2. 7. 1991  check oe array, others ok !
 *  LIB Ver      : 1.00
 * --------------------------------------------------------------------------
    dPLS152
    dPLS153
    dPLS153A
    Fuse_su		      : 1842     [46 * 42 others 2]
 * --------------------------------------------------------------------------
    dPLS155
    dPLS157
    dPLS159
    dPLS159A
    Fuse_su		      : 2108 54
 * -------------------------------------------------------------------------- */
declaration
  dataunit : bit
  ;
  functions
    Program
    Read
    Verify
    Blank_Check
    Auto
  ;
  Manufacturers
    SIGNETICS
  ;
  Devices
    dPLS152
    dPLS153
    dPLS153A
    dPLS155
    dPLS157
    dPLS159
    dPLS159A
  ;
		/*  ΥΝΝΝΝΈΥΝΝΝΝΈ        */
  chips =  C5,  /* [³ 1     20 ³] VCC   */
           C4,  /* [³ 2     19 ³] NC    */
	   C3,  /* [³ 3     18 ³] FS    */
	   C2,  /* [³ 4     17 ³] PV    */
	   C1,  /* [³ 5     16 ³] FN    */
           C0,  /* [³ 6     15 ³] R0    */
	   R6,  /* [³ 7     14 ³] R1    */
	   R5,  /* [³ 8     13 ³] R2    */
	   R4,  /* [³ 9     12 ³] R3    */
	  GND,  /* [³ 10    11 ³] STROBE*/
		/*  ΤΝΝΝΝΝΝΝΝΝΝΎ        */
	STROBE, R3, R2, R1, R0, FN, PV, FS, NC, VCC;

  $v2 = FS;
  $v3 = VCC;
endd

/* ---- PLS152, PLS153/A ------------------------------------------- */
int row_153[47] =
	      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
                10, 11, 12, 13, 14, 15, 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};
/* ---- PLS155 ----------------------------------------------------- */
int row_155[54] =
	      { 15, 14, 13, 12, 11, 10,  9,  8, 37, 36,
		39, 38, 41, 40, 43, 42,  7,  6,  5,  4,
		 3,  2,  1,  0, 32, 33, 34, 35, 44, 45,
		46, 47, 79,117, 81, 80, 94, 95,113,114,
	       115,116, 83, 82, 84, 85, 86, 87, 93, 92,
		88, 89, 90, 91};
int col_155[10] =
	      { 46, 47, 48, 49, 37, 35, 34, 36, 33, 38};
int xor_row_155[8]  =
	      {120,122,121,123,127,125,126,124};
int xor_col_155[8]  =
	      { 43, 43, 45, 45, 45, 45, 45, 45};
/* ---- PLS157 ----------------------------------------------------- */
int row_157[54] =
	      { 15, 14, 13, 12, 11, 10,  9,  8, 35, 34,
		37, 36, 39, 38, 41, 40, 43, 42, 45, 44,
		 7,  6,  5,  4,  3,  2,  1,  0, 32, 33,
		46, 47, 79,117, 81, 95,113,114,115,116,
		82, 83, 84, 85, 80, 94, 86, 87, 88, 89,
		90, 91, 92, 93};
int col_157[10] =
	      { 33, 46, 47, 48, 49, 37, 35, 36, 38, 34};
int xor_row_157[6]  =
	      {112,118,127,125,122,120};
int xor_col_157[6]  =
	      { 43, 45, 45, 45, 45, 45};
/* ---- PLS159 ----------------------------------------------------- */
int row_159[54] =
	      { 15, 14, 13, 12, 11, 10,  9,  8, 33, 32,
		35, 34, 37, 36, 39, 38, 41, 40, 43, 42,
		45, 44, 47, 46,  7,  6,  5,  4,  3,  2,
		 1,  0, 79,117,113,114,115,116, 80, 81,
		82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
		92, 93, 94, 95};
int col_159[10] =
	      { 46, 47, 48, 49, 37, 38, 35, 33, 36, 34};
int xor_row_159[4]  =
	      {127,125,122,120};
/* ----------------------------------------------------------------- */
int oe[4]   = { 41, 42, 40, 44};


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(vol2, vol3)
voltage vol2, vol3;
{
  @Vout 1,    vol2;    /* NULL */
  @Vout 2,    vol2;    /* Vp   */
  @Vout 3,    vol3;    /* Vccp */
  @Out  GND,  	 @G;
  @Delay 10, @Ms;  

  @Out VCC,     @W;
  @Out NC,      @W;
  @Out C[0..5], @W;
  @Out R[0..6], @W;
  @Out FS,      @W;
  @Out STROBE,  @W;
  @Out FN,      @Z;
  @Out PV,      @W;

  @Out VCC,     @L;
  @Out NC,      @L;
  @Out C[0..5], @L;
  @Out R[0..6], @L;
  @Out FS,      @L;
  @Out STROBE,  @H;
  @Out PV,      @L;

  @Delay 100, @Us;
}
/* -----------------------------------------------------------------------
 * Read data from device
 * Blank check
 * Verify
 * ----------------------------------------------------------------------- */
int verifyf(address, data, option)
int address, data, option;
{
  int	tmp;

  @Display 67, 9, address, @d;
  @Store tmp;

  if     (option == 'r')     @Load data;	/* Read data	   */
  else if(option == 'b') {			/* Blank check     */
    if(data&1 != 0)          @Exit;
  }
  else if(option == 'v') {			/* Verify check    */
    if ((tmp&1) != (data&1)) @Exit;
  }
  else if(option == 'p') {			/* Program verify check    */
    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,
     address;
{
  int pgm_d,					/* Program data     */
      read_d;					/* Read data        */

  pgm_d = read_d = 0;     
  
  @Set 0, address;
  @Store pgm_d;

  @Out C[0..5], i;
  @Out R[0..6], j;

  @Out VCC, @O;
  if(option == 'p' && pgm_d == 1) {
    @Out PV,    @H;
    @Out FS,    @O;
    @PinDelay STROBE, @L, @H, 10;
    @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, address;

  disp(option, 0);
  address = 0;

if(DEVICE == dPLS155) {
  init(14.5, 8.5);

  for(i=0; i<32; i++)          				/* AND, OR array */
    for(j=0; j<54; j++)
     sub(i, row_155[j], option, address++);

  for(i=0; i<10; i++)					/* OE  array */
    for(j=0; j<33; j++)
      sub(col_155[i], row_155[j], option, address++);

  for(i=0; i<34; i++) 					/* FlipFlop Control */
    sub(39, row_155[i], option, address++);

  for(i=0; i<8; i++) 					/* XOR */
    sub(xor_col_155[i], xor_row_155[i], option, address++);

  for(i=0; i<4; i++) 					/* FlipFlop Control */
    sub(39, 104+i*2, option, address++);

  for(i=0; i<4; i++) 					/* output enable */
    sub(oe[i], 118, option, address++);
}

else if(DEVICE == dPLS157) {
  init(14.5, 8.5);

  for(i=0; i<32; i++)          				/* AND, OR array */
    for(j=0; j<54; j++)
     sub(i, row_157[j], option, address++);

  for(i=0; i<10; i++)					/* OE  array */
    for(j=0; j<33; j++)
      sub(col_157[i], row_157[j], option, address++);

  for(i=0; i<34; i++) 					/* FlipFlop Control */
    sub(39, row_157[i], option, address++);

  for(i=0; i<6; i++) 					/* XOR */
    sub(xor_col_157[i], xor_row_157[i], option, address++);

  for(i=0; i<6; i++) 					/* FlipFlop Control */
    sub(39, 97+i, option, address++);

  for(i=0; i<4; i++) 					/* output enable */
    sub(oe[i], 124, option, address++);
}

else if(DEVICE == dPLS159 || DEVICE == dPLS159A) {
  init(14.5, 8.5);

  for(i=0; i<32; i++)          				/* AND, OR array */
    for(j=0; j<54; j++)
     sub(i, row_159[j], option, address++);

  for(i=0; i<10; i++)					/* OE  array */
    for(j=0; j<33; j++)
      sub(col_159[i], row_159[j], option, address++);

  for(i=0; i<34; i++) 					/* FlipFlop Control */
    sub(39, row_159[i], option, address++);

  for(i=0; i<8; i++) 					/* FlipFlop Control */
    sub(39, 96+i, option, address++);

  for(i=0; i<4; i++) 					/* XOR */
    sub(45, xor_row_159[i], option, address++);

  for(i=0; i<4; i++) 					/* Output Enable */
    sub(oe[i], 118, option, address++);
}

else if(DEVICE == dPLS152 || DEVICE == dPLS153 || DEVICE == dPLS153A)
{
  init(17.50, 8.75);

  for(i=0; i<32; i++)          			/* AND, OR array */
    for(j=0; j<46; j++)
      sub(i, row_153[j], option, address++);

  for(i=0; i<10; i++)				/* OE  array */
    for(j=0; j<36; j++)
      sub(i+32, row_153[j], option, address++);

  for(i=0; i<10; i++) {				/* XOR array */
    sub(51-i, 58, option, address++);
  }
}

  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 ------------------------ */
 