/* ----------------------------------------------------------------P. S. O---
 *  FIRST UPDATE : Dec. 17. 1990  check security !
 *                   2.  4. 1991  all ok!
 *  LIB Ver      : 1.00
 * --------------------------------------------------------------------------
 * Fuse_su		      : 2560     [40 * 64]
 * Internal Security Fuse     : 1
 * -------------------------------------------------------------------------- */
declaration
  dataunit : bit 
  ;
  functions
    Program
    Read
    Verify
    Blank_Check
    Security
    Auto
  ;
  Manufacturers
    SIGNETICS
  ;
  Devices
    dPLUS20L8D	 /* 10ns */
    dPLUS20R4D   /* 10ns */ 
    dPLUS20R6D   /* 10ns */ 
    dPLUS20R8D   /* 10ns */ 
  ;
		/*  ΥΝΝΝΝΈΥΝΝΝΝΈ        */
  chips =  FS,  /* [³ 1     24 ³] VCC   */
      VFS:CS0,  /* [³ 2     23 ³] PV    */
	  CS1,  /* [³ 3     22 ³] FN    */
          CS2,  /* [³ 4     21 ³] NC4   */
	  CS3,  /* [³ 5     20 ³] NC3   */
	  CS4,  /* [³ 6     19 ³] NC2   */
	  CS5,  /* [³ 7     18 ³] NC1   */
          CS6,  /* [³ 8     17 ³] NC0   */
	  RS0,  /* [³ 9     16 ³] RS5   */
	  RS1,  /* [³ 10    15 ³] RS4   */
	  RS2,  /* [³ 11    14 ³] RS3   */
	  GND,  /* [³ 12    13 ³] STROBE*/
		/*  ΤΝΝΝΝΝΝΝΝΝΝΎ        */
	STROBE, RS3, RS4, RS5, NC0, NC1, NC2, NC3, NC4, FN, PV, VCC;
	
  $v2 = FS, VFS;
  $v3 = VCC;
endd

int disp_flag, index;
/* -----------------------------------------------------------------------
 * 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,    14.75;	/* NULL */
  @Vout 2,    14.75;    /*      */
  @Vout 3,     8.75;    /* Vccp */
  @Out  GND,  	 @G;
  @Delay 10, @Ms;  

  @Out VCC,     @W;
  @Out NC[0..4],@W;
  @Out CS[0..6],@W;
  @Out RS[0..5],@W; 
  @Out FS,      @W;
  @Out VFS,     @W;
  @Out STROBE,  @W;
  @Out FN,      @Z;
  @Out PV,      @W;
  
  @Out VCC,     @L;
  @Out NC[0..4],@L;
  @Out CS[0..6],@L;
  @Out RS[0..5],@L; 
  @Out FS,      @L;
  @Out VFS,     @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;

  @Store 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    */
    if ((tmp&1) != (data&1)) @Exit;
  }
  else if(option == 'p') {			/* Program verify check    */
    if ((tmp&1) != (data&1)) @Exit;
  }   
  else if(option == 's') {			/* Security Verify  */
    if(data & 1 != 1)        @Exit;
  }
}
/* -----------------------------------------------------------------------
 * 1 bit(s) data process
 * ----------------------------------------------------------------------- */
int top(option)
int option;   					/* Read, Program.. or more */
{
  int i, j,
      pgm_d,					/* Program data     */
      read_d;					/* Read data        */
      
  disp(option, 0);
  pgm_d = read_d = 0;     
  
  init();
  
  for(i=0; i<64; i++) {
    for(j=0; j<40; j++) { 
      @Set 0, i*40+j;
      @Store pgm_d;
         
      @Out CS[0..6], i;
      @Out RS[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, 10;
        @Out FS,    @F; 
        @Out PV,    @L;
        }
      }
      @Out STROBE, @L; 
      @In FN, read_d;
      @Out STROBE, @H;
      @Out VCC,   @F;
      verifyf(i*40+j, read_d, option);
    }
  }
  disp(option, 1);
}
/* -----------------------------------------------------------------------
 * Security device
 * ----------------------------------------------------------------------- */
int security_device()
{
  int tmp, read_d;
  
  disp('s', 0);

  init();

  @Out CS[0..6], 72;
  @Out RS[0..5], 65;
  @Out VCC,     @O; 
  @Out PV,      @H;
  @Out VFS,     @O;
  @PinDelay STROBE, @L, @H, 10;
  @Out VFS,     @F; 
  @Out PV,      @L;
  @Out VCC,     @F;
  disp_flag = 1;
  top('s');
  disp_flag = 0;
  disp('s', 1);
}
/* -----------------------------------------------------------------------
 * MAIN Program
 * ----------------------------------------------------------------------- */
int main()
{
  index = 6;
  disp_flag = 0;

  if     (FUNCTION == Program) {
    top('p');					/* Program device     */
    top('v');					/* Verify device      */
  }
  else if(FUNCTION == Security) {
    security_device();				/* Security 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      */
    security_device();	                        /* Security device    */
  }
}
/* ------------------------------- End of program ------------------------ */
 