/* ----------------------------------------------------------------P. S. O---
 *  FIRST UPDATE : 2. 7. 1991.  (p, r, v, b, a) all ok !
 *  LIB Ver      : 1.00
 * --------------------------------------------------------------------------
 * Fuse_su		      : 2452  62
 * -------------------------------------------------------------------------- */
declaration
  dataunit : bit 
  ;
  functions
    Program
    Read
    Verify
    Blank_Check
    Auto
  ;
  Manufacturers
    SIGNETICS
  ;
  Devices
    dPLS179
  ;
		/*  ΥΝΝΝΝΈΥΝΝΝΝΈ        */
  chips =  C0,  /* [³ 1     24 ³] VCC   */
           C1,  /* [³ 2     23 ³] NC4   */
	   C2,  /* [³ 3     22 ³] FS    */
	   C3,  /* [³ 4     21 ³] PV    */
	   C4,  /* [³ 5     20 ³] FN    */
           C5,  /* [³ 6     19 ³] NC3   */
	  NC0,  /* [³ 7     18 ³] NC2   */
	   R0,  /* [³ 8     17 ³] NC1   */
	   R1,  /* [³ 9     16 ³] R6    */
	   R2,  /* [³ 10    15 ³] R5    */
	   R3,  /* [³ 11    14 ³] R4    */
	  GND,  /* [³ 12    13 ³] STROBE*/
		/*  ΤΝΝΝΝΝΝΝΝΝΝΎ        */
	STROBE, R4, R5, R6, NC1, NC2, NC3, FN, PV, FS, NC4, VCC;
  $v2 = FS;
  $v3 = VCC;
endd

int row[62] = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
               0x05, 0x04, 0x03, 0x02, 0x01, 0x00, 0x40, 0x41, 0x21, 0x20,
               0x23, 0x22, 0x25, 0x24, 0x27, 0x26, 0x29, 0x28, 0x2b, 0x2a,
               0x2d, 0x2c, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x2f, 0x2e,
               0x4f, 0x75, 0x71, 0x72, 0x73, 0x74, 0x50, 0x51, 0x52, 0x53,
               0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
               0x5e, 0x5f};
int col[10] = {0x2e, 0x2f, 0x30, 0x2b, 0x25, 0x26, 0x23, 0x21, 0x24, 0x22};
int xor_row[4]  =
              {0x7f, 0x7d, 0x7a, 0x78};
int xor_col[4]  =
              {0x33, 0x2d, 0x2d, 0x2d};
int arch[4] = {0x2a, 0x29, 0x2c, 0x28};

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.70;    /* Vccp */
  @Out  GND,  	 @G;
  @Delay 10, @Ms;

  @Out VCC,      @W;
  @Out NC[0..4], @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[0..4], @L;  
  @Out C[0..5],  @L;
  @Out R[0..6],  @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..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, k;

  disp(option, 0);

  init();

  k = 0;

  for(i=0; i<32; i++) {					/* AND, OR array */
    for(j=0; j<62; j++) {
      sub(i, row[j], option, k++);
    }
  }

  for(i=0; i<10; i++) {					/* OE array */
    for(j=0; j<41; j++) {
      sub(col[i], row[j], option, k++);
    }
  }

  for(i=0; i<42; i++) {					/* FlipFlop Control */
    sub(0x27, row[i], option, k++);
  }
  for(i=0; i<8; i++) {					/* FlipFlop Control */
    sub(0x27, 0x60+i, option, k++);
  }
  for(i=0; i<4; i++) {					/* xor */
    sub(xor_col[i], xor_row[i], option, k++);
  }
  for(i=0; i<4; i++) {					/* output enable */
    sub(arch[i], 0x77, 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 ------------------------ */
 