/**********************************************
	Device name     : Intel 8748
        PROG Volt	: 18.0 V
        EA   Volt	: 19.0 V	
 	VDD  Volt	: 25.0 V
	Date	        : 11. 27. 1990
	Last Modify date:  2. 26. 1991
	Author		: E. Y. Lee
***********************************************/
declaration
  dataunit : byte;
  
  functions
    Program
    Read  
    Verify
    Blank_check
    Data_compare
    Auto
  ;
  Manufacturers
    INTEL
  ;
  Devices
    D8748
  ;

  chips =
         /*  ÕÍÍÍÍÍÍÍÍÍ¸       */
  T0,    /* o³01     40³o VCC  */
  XTAL0, /* o³02     39³o T1   */
  XTAL1, /* o³03     38³o NC14 */
  RESET, /* o³04     37³o NC13 */
  NC0,   /* o³05     36³o NC12 */
  INT_,  /* o³06     35³o NC11 */
  EA,    /* o³07     34³o NC10 */
  NC1,   /* o³08     33³o NC9  */
  NC2,   /* o³09     32³o NC8  */
  NC3,   /* o³10     31³o NC7  */
  NC4,   /* o³11     30³o NC6  */
  A0:D0, /* o³12     29³o NC5  */
  A1:D1, /* o³13     28³o P11  */
  A2:D2, /* o³14     27³o P10  */
  A3:D3, /* o³15     26³o Vdd  */
  A4:D4, /* o³16     25³o PROG */
  A5:D5, /* o³17     24³o P23  */
  A6:D6, /* o³18     23³o P22  */
  A7:D7, /* o³19     22³o A9   */
  GND,   /* o³20     21³o A8   */

  A8,  A9,   P22_, P23_, PROG, VDD,   P10_,  P11_,  NC5, NC6,
  NC7, NC8,  NC9,  NC10, NC11, NC12,  NC13,  NC14,  T1,  VCC;

  $v1 = VDD;
  $v2 = EA, PROG;
  $v3 = VCC;
endd

/* -----------------------------------------------------------------------
 * init () ---> Initial processing
 * ----------------------------------------------------------------------- */
int     init ()
{
int i;

   @Vout 1, 5.0;
   @Vout 2, 18.0;
   @Vout 3, 5.0;            /* Voltage Source #3 */
   @Out GND      , @G;       /* Ground output */
   @Delay  10,	   @Ms;

   @Out NC[0..1] , @Z;
   @Out NC[9..14], @Z;
   @Out NC[2..8] , @W;
   @Out INT_     , @W;
   @Out EA	 , @W;
   @Out P22_     , @W;
   @Out P23_	 , @W;
   @Out PROG	 , @W;
   @Out VDD	 , @W;
   @Out P10_	 , @W;
   @Out P11_	 , @W;
   @Out T0	 , @W;
   @Out T1	 , @W;
   @Out XTAL0    , @Z;
   @Out XTAL1    , @Z;
   @Out RESET    , @W;

   @Out D [0..7] , @Z;
   @Out A [0..9] , @W;

   @Out XTAL0    , @C;
   @Out XTAL1    , @C;
   @Out A[0..9]  , @L;
   @Out NC[2..8] , @L;
   @Out RESET    , @L;
   @Out INT_     , @H;
   @Out EA	 , @H;
   @Out P22_     , @L;
   @Out P23_	 , @L;
   @Out VDD	 , @H;
   @Out P10_	 , @L;
   @Out P11_	 , @L;
   @Out T0	 , @L;
   @Out T1	 , @H;
   
   @Out VDD      , @O;   

   @Out VCC      , @O;       /* Vcc Enable */
   for(i=0; i<10; i++)     @Delay 999, @us;

   @Out EA, @O;
}
/* ----------------------------  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;
}
/* -----------------------------------------------------------------------
 * read () ---> read processing
 * ----------------------------------------------------------------------- */
int read (option)
int option ;
{
  int  i, j;
  int  tmp, tmp1;
  int  saddr, eaddr;

  @Set B_HADDR, B_LADDR;
  init ();
  tmp = tmp1 = 0;
  @Out  PROG,   @L;
  for (i=S_LWHB ; i<=E_LWHB; i++) {
    @Display  68, 9, i;  
    @Out A [8..9], i;   		/* High byte address output */
    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], @W;
	@Out A [0..7], j; 		/* Low  byte address output */
	@Delay 10, @us;
	@Out T0      , @H;
	@Out RESET   , @H;

	@Out D [0..7], @Z;
	@In  D [0..7], tmp;
	@Out T0      , @L;
	@Out RESET   , @L;

	if( option == 1 ) @Load tmp;
        else if(option == 3 ) {
            if(tmp != 0)         Failf( 0, 0, i, j, tmp);
        }
        else if(option == 2) {
          @Store tmp1;
          if(tmp != tmp1)      Failf ( 0, 0, i, j, tmp);
        }
	else if( option == 4)   {
	  @Store tmp1;
	  @Compare tmp, tmp1;
        }
        
	@Inc SPLIT;
      }
   }
}
/* -----------------------------------------------------------------------
 * program () ---> Program processing
 * ----------------------------------------------------------------------- */
int program ()
{
  int i, j, failcnt;
  int p_data, v_data;
  int saddr, eaddr;

  failcnt = 0;
  @Set  B_HADDR, B_LADDR;
  init ();
  for (i=S_LWHB; i<=E_LWHB; i++) {
    @Display 68, 9, i;
    @Out A [8..9], i;   			/* Output High word address */
    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++) {
      p_data = v_data = 0;

      @Out A [0..7], @W;
      @Out A [0..7], j; 			/* Low  byte address output */
      @Delay 10, @us;            
      @Out RESET   , @H;
      
      @Store p_data;
      @Out D [0..7], @W;
      @Out D [0..7], p_data;
      @Raising VDD, 5.0, 25.0, 90;
      @Out PROG    , @O;
      @Delay 999, @Us;
      @Delay 999, @Us;
      @Out PROG    , @F;
      @Falling VDD, 25.0, 5.0, 90;

      @Out T0      , @H;
      @Out D [0..7], @Z;		/* Byte verify */
      @Delay 150   , @Us;
      @In  D [0..7], v_data;		
      @Out T0      , @L;
      @Out RESET   , @L;
      
      if(v_data != p_data) {
        if(failcnt < LOP ) {  failcnt++;   j-=1;  continue; }
        else       Failf( 0, 0, i, j, v_data);
      }
      else failcnt = 0;
      
      @Inc SPLIT;
    }
  }
}
/* -----------------------------------------------------------------------
 * main () ---> Controll main
 * ----------------------------------------------------------------------- */
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!";
  }
} 
/* ---------------------------- End of program --------------------------- */  
