/********************************************
	Device name     : AMD 8753H
	Date            : 1. 23. 1991
	Last Modify date: 2. 26. 1991
	Author		: E. Y. Lee
********************************************/
declaration
  dataunit : byte
  ;
  functions
  	Program
  	Read 
  	Verify
  	Blank_check
  	Data_compare
  	Auto
  ;
  Manufacturers
  	AMD
  ;
  Devices
  	D8753H
  ;
  chips =                  ÕÍÍÍÍÍÍÍÍÍÍÍÍ¸
          A0,     /* P10   ³ 1       40 ³   Vcc       */
          A1,     /* P11   ³ 2       39 ³   P00, AD0  */
          A2,     /* P12   ³ 3       38 ³   P01, AD1  */
          A3,     /* P13   | 4       37 ³   P02, AD2  */
          A4,     /* P14   ³ 5       36 ³   P03, AD3  */
          A5,     /* P15   ³ 6       35 ³   P04, AD4  */
          A6,     /* P16   ³ 7       34 ³   P05, AD5  */
          A7,     /* P17   ³ 8       33 ³   P06, AD6  */
          RST,    /*       ³ 9       32 ³   P07, AD7  */
          NC0,    /* P30   ³ 10      31 ³   EA_	      */
          NC1,    /* P31   ³ 11      30 ³   ALE	      */
          NC2,    /* P32   ³ 12      29 ³   PSEN_     */
          NC3,    /* P33   ³ 13      28 ³   P27       */
          NC4,    /* P34   ³ 14      27 ³   P26       */
          NC5,    /* P35   ³ 15      26 ³   P25, NC8  */
          NC6,    /* P36,WR³ 16      25 ³   P24, A12  */
          NC7,    /* P37,RD³ 17      24 ³   P23, A11  */
          XTAL2,  /*       ³ 18      23 ³   P22, A10  */
          XTAL1,  /*       ³ 19      22 ³   P21, A9   */
          GND,    /*       ³ 20      21 ³   P20, A8   */
		  /*       ÔÍÍÍÍÍÍÍÍÍÍÍÍ¾             */

          A8, A9, A10, A11, A12, NC8, P26, P27, PSEN_, ALE,
          EA_, Q7, Q6, Q5, Q4, Q3, Q2, Q1, Q0, Vcc
  ;
  $v2 = EA_;
  $v3 = Vcc;
endd
/* --------------------------------------------------------------------- */
int  init ()
{
  @Vout   1,  5.0;
  @Vout   2, 21.0;
  @Vout   3,  5.0;
  @Out   GND,  @G;
  @Delay 10,   @Ms;
  
  @Out  A[0..12],@W;
  
  @Out  Q[0..7], @Z;
  @Out  NC[0..8],@W;
  @Out  XTAL1,   @Z;
  @Out  XTAL2,   @Z;

  @Out  RST,     @W;    
  @Out  P26,     @W;
  @Out  P27,     @W;
  @Out  PSEN_,   @W;
  @Out  EA_,     @W;
  @Out  ALE,     @W;
  
  @Out  XTAL2,   @C;
  @Out  XTAL1,   @C;
  
  @Out  NC[0..8],@L;
  @Out  Vcc,     @L;
  @Out  A[0..12],@L;
  @Out  Vcc,     @O;
  @Delay  999,   @Us;
}
/* ----------------------------  FAIL  -------------------------------- */
int  Failf ( hwhb, hwlb, lwhb, lwlb, data )
int  hwhb, hwlb, lwhb, lwlb, data;
{
  int  high, low;

  high = ( hwhb << 8 ) | hwlb;
  low  = ( lwhb << 8 ) | lwlb;
  @Fail  high, low, data;
}
/* --------------------------------------------------------------------- */
int  read(option)
int  option;
{
  int  i, j;
  int  tmp, tmp2;
  int  saddr, eaddr;

  @Set  B_HADDR,  B_LADDR;  
  tmp = tmp2 = 0;
  init();
  @Out  PSEN_,   @L;
  @Out  P26,     @L;
  @Out  P27,     @L;
  
  for(i=S_LWHB;i<=E_LWHB;i++)
  {
     @Display  68, 9, i;
     @Out   A[8..12],  i;
     if( i == S_LWHB )  saddr = S_LWLB;
     else		saddr = 0;
     if( i == E_LWHB )  eaddr = E_LWLB;
     else		eaddr = 0xff;     
     for(j=saddr;j<=eaddr;j++)
     {
       @Out  A[0..7],   j;
       @Out  RST,      @H;
       @Out  PSEN_,    @L;
       @Out  ALE,      @H;
       @Out  EA_,      @H;
       @Out  P26,      @L;
       @Out  P27,      @L;
       
       @In   Q[0..7],  tmp;
       
       if( option == 1 )           @Load tmp;
       else if( option == 4 )      {
            @Store  tmp2;
            @Compare tmp, tmp2;
       }
       else if( option == 3 )
       {
            if( tmp != 0xff )        Failf (0, 0, i, j, tmp);
       }
       else if( option == 2 )
       {
            @Store  tmp2;
            if( tmp != tmp2 )        Failf( 0, 0, i, j, tmp);
       }       @Inc  SPLIT;
     } /* for j */
  }  /* for i */
}       
/* --------------------------------------------------------------------- */
int   program()
{
  int i, j, failcnt;
  int tmp, tmp2;
  int saddr, eaddr;
  
  failcnt = 0;
  tmp = tmp2 = 0;
  @Set  B_HADDR,  B_LADDR;
  init();
  for(i=S_LWHB;i<=E_LWHB;i++)
  {
     @Display  68, 9, i;
     @Out   A[8..12], i;
     if( i == S_LWHB )  saddr = S_LWLB;
     else		saddr = 0;
     if( i == E_LWHB )  eaddr = E_LWLB;
     else		eaddr = 0xff;     
     for(j=saddr;j<=eaddr;j++)
     {
       @Store  tmp; 
       @Out  Q[0..7],@W;
       @Out  RST,    @H;
       @Out  ALE,    @H;
       @Out  EA_,    @H;
       @Out  PSEN_,  @L;
       @Out  P26,    @L;
       @Out  P27,    @H;
       
       @Out  A[0..7], j;
       @Out  EA_,    @O;
       @Out  Q[0..7], tmp;
       @Out  ALE,    @L;
       @Delay  2,    @Ms;
       @Out  ALE,    @H;
       @Out  EA_,    @F;

       @Out  EA_,    @H;
       @Out  Q[0..7],@Z;
       @Out  P27,    @L;
       @In   Q[0..7],tmp2;
                          
       if( tmp != tmp2)
       {
          if( failcnt > LOP )       Failf( 0, 0, i, j, tmp2);
          else     failcnt ++;
          j -= 1;
       }
       else 
       {  failcnt = 0;
          @Inc  SPLIT;
       }
     }  /* for j */
  }  /* for i */
}
/* --------------------------------------------------------------------- */
int  main()
{
  if( FUNCTION == Read)	     {
  	@Display 26, 6, "Reading...";
  	read(1);
  	@Display 26, 6, "Read OK!  ";
  	@CheckSumOn;
  }
  else if( FUNCTION == Program)	 {
  	@Display 26, 6, "Programming...";
  	program();
  	@Display 26, 6, "Program OK!   ";
  	@Display 26, 7, "Verifying...";
  	read(2);
  	@Display 26, 7, "Verification OK!";
  }  	
  else if( FUNCTION == Verify)	 {
  	@Display 26, 6, "Verifying...";
  	read(2);
  	@Display 26, 6, "Verification OK!";
  }
  else if( FUNCTION == Blank_check)  {
  	@Display 26, 6, "Blank checking...";
  	read(3);
  	@Display 26, 6, "Blank check OK!  ";
  }
  else if( FUNCTION == Data_compare)  {
  	@Display 26, 6, "Data comparing...";
  	read(4);
  	@Display 26, 6, "Data comparison OK!";
  }
  else if( FUNCTION == Auto)     {
	@Display 26, 6, "Blank checking...";  
  	read(3);
  	@Display 26, 6, "Blank check OK!  ";
  	@Display 26, 7, "Programming...";
  	program();
  	@Display 26, 7, "Program OK!   ";
  	@Display 26, 8, "Verifying...";
  	read(2);
  	@Display 26, 8, "Verification OK!";
  }
} 
/*--------------------------------------------------------------------- */