/* --------------------------------------------------------------------- */
declaration
  dataunit : byte;
  functions
    Program
  ;
  Manufacturers
    RAM
  ;
  Devices
    PD4164
  ;
  chips = NC, DIN, WE_, RAS_, A0, A2, A1, Vcc,
  	  A7, A5, A4, A3, A6, DOUT, CAS_, GND
  ;
  $v2 = Vcc, RAS_, CAS_; 
endd

int  init()
{
  @Vout  1,  5.0;
  @Vout  2,  5.0;
  @Vout  3,  5.0;
  @Out   GND, @G;
  @Delay 10, @Ms;
  
  @Out   NC,    @W;
  @Out   A[0..7],@W;
  @Out   DIN,   @W;
  @Out   WE_,   @W;
  @Out   RAS_,  @W;
  @Out   Vcc,   @W;
  @Out   DOUT,  @Z;
  @Out   CAS_,  @W;

  @Out   A[0..7],@L;                
  @Out   DIN,   @L;
  @Out   WE_,   @H;
  @Out   RAS_,  @O;
  @Out   CAS_,  @O;
  @Out   NC,    @L;
  @Out   Vcc,   @L;

  @Out   Vcc,   @O;  
  @Delay 50, @Ms;
}
/* --------------------------------------------------------------------- */ 
int  main()
{
  int  tmp;
  int  i, j, k;
   
  init();
  tmp = 0;  
  @Display 24, 14, "Current : ";
  for( i=0; i<256; i++ )
  {
   for( j=0;j<256;j++)
   {
     @Display  34, 14, (i* 256)+j, @D;   
     for( k=0;k<2;k++)
     {
/* ------------------------ Write cycle ------------------- */
       @Out  DIN,  k;
       @Out  A[0..7], i;
       @Out  RAS_, @F;
       @Out  WE_,  @L;
       @Out  A[0..7], j;
       @Out  CAS_, @F;

       @Out  WE_,  @H;
       @Out  RAS_, @O;
       @Out  CAS_, @O;       
       
/* ------------------------ Read cycle -------------------- */     

       @Out  A[0..7], i;
       @Out  RAS_, @F;
     
       @Out  A[0..7], j;     
       @Out  CAS_, @F;

       @In   DOUT, tmp;
       @Out  RAS_, @O;
       @Out  CAS_, @O;
       
       if( k&0x01 != tmp&0x01 )    @Fail  i, j, tmp;
/* ------------------------ Read end ---------------------- */
     } /* end for k */
    } /* end for j */
  } /* end for i */
}        
