/* --------------------------------------------------------------------- */
declaration
  dataunit : byte;
  functions
    Test
  ;
  Manufacturers
    RAM
  ;
  Devices
    PD414256
  ;
  chips = D0, D1, WE_, RAS_, NC, A0, A1, A2, A3, Vcc,
  	  A4, A5, A6, A7, A8, OE_, CAS_, D3, D2, 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   A[0..7], @W;
  @Out   A8,      @W;
  @Out   NC,      @W;
  @Out   D[0..3], @Z;
  @Out   WE_,   @W;
  @Out   RAS_,  @W;
  @Out   Vcc,   @W;
  @Out   CAS_,  @W;
  @Out   OE_,   @W;
  
  @Out   A[0..7], @L;
  @Out   A8,    @L;
  @Out   NC,    @L;
  @Out   WE_,   @H;
  @Out   RAS_,  @O;
  @Out   CAS_,  @O;
  @Out   Vcc,   @L;
  @Out   OE_,   @H;

  @Out   Vcc,   @O;  
  @Delay 50, @Ms;
}
/* --------------------------------------------------------------------- */ 
int  main()
{
  int  tmp, tmp1, sum;
  int  i, j, k, m, l; 
   
  init();
  tmp = 0;  
  @Display  24, 14, "Current : ";
  for( m=0; m<2; m++)
  { 
    for( i=0; i<256; i++ )
    {
     for( l=0;l<2;l++)
     for( j=0;j<256;j++)
     {
       sum = (m*256) + i;
       sum = sum * 512 + ( l*256)+j;
       @Display  34, 14, sum, @D;
       for( k=0;k<2;k++)
       {
       if(k==0)    tmp1 = 0;
       else        tmp1 = 0x0f;                   
/* ------------------------ Write cycle ------------------- */
       @Out  D[0..3], @W;
       @Out  D[0..3], tmp1;
       @Out  A8,      m;
       @Out  A[0..7], i;
       @Out  RAS_, @F;
       @Out  WE_,  @L;
       @Out  A8,      l;
       @Out  A[0..7], j;
       @Out  CAS_, @F;

       @Out  WE_,  @H;
       @Out  RAS_, @O;
       @Out  CAS_, @O;       
       
/* ------------------------ Read cycle -------------------- */     

       @Out  D[0..3], @Z;
       @Out  A8,      m;
       @Out  A[0..7], i;
       @Out  RAS_, @F;
     
       @Out  A8,      l;                   
       @Out  A[0..7], j;     
       @Out  CAS_, @F;
       @Out  OE_,  @L;
       @In   D[0..3], tmp;
       @Out  OE_,  @H;
       @Out  RAS_, @O;
       @Out  CAS_, @O;
       
       if( tmp != tmp1 )    @Fail  i, j, tmp;
/* ------------------------ Read end ---------------------- */
     } /* end for k */
    } /* end for j */
  } /* end for i */
 } /* end for m */
}        
