home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / V12N16.ZIP / XMS.ZIP / XMSTEST.PAS < prev   
Pascal/Delphi Source File  |  1992-01-05  |  2KB  |  58 lines

  1. {$X+}
  2. Program XMSTest;
  3. USES crt, XMS;
  4. CONST
  5.   NumVars     = 131072;   { 131072 total no of variables in array }
  6.   BytesPerVar = 4;        { ie. 2 for integers, 4 for LongInts ...}
  7. VAR
  8.   I       : LongInt;
  9.   Result  : LongInt;
  10.   Hdl     : Word;          { Handle for Extended memory allocated }
  11.   HiMemOK : boolean;
  12. BEGIN
  13.   ClrScr;
  14.   HiMemOK := XMSDriverLoaded;
  15.   WriteLn('HIMEM.SYS Driver Loaded=', HiMemOK);
  16.   IF NOT HiMemOK THEN Halt;
  17.   WriteLn('Total Extended Memory: ', XMSTotalMemoryAvailable, ' KB');
  18.   WriteLn('Largest Free Extended Memory Block: ',
  19.            XMSLargestBlockAvailable, ' KB');
  20.  
  21.   {Allocate Memory - Hdl is memory block handle or identifier}
  22.   Hdl := XMSAllocateBlock((NumVars * BytesPerVar + 1023) DIV 1024);
  23.          {1023 to Round Up to next KB}
  24.   WriteLn((NumVars * BytesPerVar + 1023) DIV 1024,'KB Handle=',Hdl);
  25.   WriteLn('Total Extended Memory Available After Allocation: ',
  26.           XMSTotalMemoryAvailable, ' KB');
  27.  
  28.   { Fill the variables with 1 ... NumVars for exercise }
  29.   WriteLn('Filling Memory Block ');
  30.   FOR I := 1 TO NumVars DO
  31.     BEGIN
  32.       { parameters in Move Data are - Address of Data to Move
  33.                                     - Number of Bytes
  34.                                     - Memory Handle
  35.                                     - Offset in XMS Area }
  36.       IF NOT XMSMoveDataTo(@I, BytesPerVar, Hdl, (I - 1) *
  37.         BytesPerVar) THEN
  38.         WriteLn('Error on Move to XMS: ',I,' Error: ', XMSErrorCode);
  39.       IF I MOD 1024 = 0 THEN Write(I:6,^M);
  40.     END;
  41.   WriteLn;
  42.   { Now read a couple of locations just to show how}
  43.   I := 1;  { First Element }
  44.   IF NOT XMSGetDataFrom(Hdl, (I - 1) * BytesPerVar,
  45.     BytesPerVar, @Result) THEN
  46.     WriteLn('Error on XMSGetDataFrom')
  47.     ELSE WriteLn('XMS Data [',I,']=',Result); { Print it }
  48.   I := NumVars;  { Last Element }
  49.   IF NOT XMSGetDataFrom(Hdl, (I - 1) * BytesPerVar, BytesPerVar,
  50.     @Result) THEN
  51.     WriteLn('Error on XMSGetDataFrom')
  52.     ELSE WriteLn('XMS Data [',I,']=',Result); { Print it }
  53.  
  54.   WriteLn('Release status=', XMSReleaseBlock(Hdl));
  55.   WriteLn('Press a key.');
  56.   ReadKey;
  57. END.
  58.