home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / EMSARRAY.ZIP / EMSTEST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-16  |  3.2 KB  |  112 lines

  1. Program Test_EMS_Unit;
  2.  
  3. {----------------------------------------------------------------}
  4. { This simple program test whether EMM exists, if it does exists,}
  5. { all pages are allocated to create the largest possiable array  }
  6. { in EMS, then it will be written and read in three array types  }
  7. {----------------------------------------------------------------}
  8.  
  9. Uses EMS;
  10.  
  11. Var
  12.    A                         : EMSArray;
  13.    Pages,
  14.    KiloByte,
  15.    EachPage,
  16.    EachElement,
  17.    ElementNum                : Word;
  18.  
  19.    Procedure ReadAndWrite(ArrayType: Byte);
  20.     Var
  21.       VerifyFail : Boolean;
  22.  
  23.      Begin
  24.      {----------------------------------}
  25.      { Write and Read each page in      }
  26.      { in  ArrayType:                   }
  27.      {  ArrayType = 1  Byte    Array    }
  28.      {  ArrayType = 2  Integer Array    }
  29.      {  ArrayType = 3  Real    Array    }
  30.      {----------------------------------}
  31.      Case ArrayType of
  32.        1: ElementNum := PAGESIZE DIV Sizeof(Byte);
  33.        2: ElementNum := PAGESIZE DIV Sizeof(Integer);
  34.        3: ElementNum := PAGESIZE DIV Sizeof(Real);
  35.      End;
  36.      WriteLn('Each element of the array is writing ...');
  37.      For EachPage := 0 to Pages-1 Do
  38.         Begin
  39.           { Map in a logical page to physical page 0 }
  40.           A.MapIn(EachPage, 0);
  41.           For EachElement := 1 To ElementNum Do
  42.            Case ArrayType of
  43.             1: A.ByteArry^[ EachElement ] := 10;
  44.             2: A.IntArry^[ EachElement ] := 25;
  45.             3: A.RealArry^[ EachElement ] := 3.5;
  46.            End;
  47.         End;
  48.  
  49.      WriteLn('Reading back each element of array and verifying...');
  50.      For EachPage := 0 to Pages-1 Do
  51.         Begin
  52.           { Map in a logical page to physical page 0 }
  53.           A.MapIn(EachPage, 0);
  54.           For EachElement := 1 To ElementNum Do
  55.            Case ArrayType of
  56.             1: VerifyFail := (A.ByteArry^[ EachElement ] <> 10);
  57.             2: VerifyFail := (A.IntArry^[ EachElement ] <> 25);
  58.             3: VerifyFail := (A.RealArry^[ EachElement ] <> 3.5);
  59.            End;
  60.              If VerifyFail Then
  61.                Begin
  62.                  WriteLn('Verify failed!');
  63.                  Halt(1);
  64.                End;
  65.         End;
  66.  
  67.      End;  {  **** ReadAndWrite Procedure **** }
  68.  
  69. Begin
  70.   If A.Ems_Installed Then
  71.     Begin
  72.      Pages:=A.Pages_Available;
  73.      KiloByte := Pages * 16;
  74.      WriteLn('There are ', Pages, ' pages expand memory, That is ',
  75.               KiloByte, ' Kb!');
  76.      A.Alloc(Pages);
  77.  
  78.      {----------------------------------}
  79.      { If There are some probles, Exit  }
  80.      {----------------------------------}
  81.      If EmsError<>0 Then
  82.        Begin
  83.         WriteLn ('Alloc ', Pages, ' Pages Error!' );
  84.         A.Release;
  85.         Halt(1);
  86.        End;
  87.  
  88.      WriteLn;
  89.      WriteLn('Read and Write as *Integer* Array');
  90.      ReadAndWrite(2);
  91.      WriteLn('Verify Passed, Good!');
  92.  
  93.      WriteLn;
  94.      WriteLn('Read and Write as *Real* Array');
  95.      ReadAndWrite(3);
  96.      WriteLn('Verify Passed, Good!');
  97.  
  98.      WriteLn;
  99.      WriteLn('Read and Write as *Byte* Array');
  100.      ReadAndWrite(1);
  101.      WriteLn('Verify Passed, Good!');
  102.  
  103.      A.Release
  104.     End
  105.   Else
  106.     Begin
  107.      WriteLn('EMM does not exists');
  108.      Halt(1);
  109.     End;
  110. End.
  111.  
  112.