home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP5_EMS.ZIP / EMSTEST.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1990-03-15  |  6.2 KB  |  234 lines

  1. Program EMSTest;
  2.  
  3. {Demonstrate Expanded Memory Specification (LIM 3.2 and 4.0) Use in TP 5.5}
  4.  
  5. {This is a very simple EMS test program.  It checks for a valid EMS driver,
  6.  checks for a hardware/driver error, allocates the number of free EMS pages
  7.  unused, then runs through four phases of writing bit maps to the EMS pages
  8.  and reading them to see if there were any errors.  This program wouldn't
  9.  be extensive enough for a thorough EMS test, but it gives you the idea of
  10.  how to program EMS access in Turbo Pascal version 5.x.}
  11.  
  12. Uses
  13.    DOS,
  14.    CRT;
  15.  
  16. Var
  17.    Regs      : Registers;
  18.    EMS_Error : boolean;
  19.  
  20. Function EMS_Installed : boolean;
  21. {Return TRUE if an EMS driver is installed, FALSE otherwise}
  22. Var
  23.    S : string[8];
  24. Begin
  25.    With Regs Do
  26.    Begin
  27.       AH := $35;
  28.       AL := $67;
  29.       MSDos(Regs);
  30.       Move(Mem[ES:$0A],S[1],8);
  31.       S[0] := #8;
  32.       EMS_Error := False;
  33.       EMS_Installed := (S = 'EMMXXXX0');
  34.    End;
  35. End;
  36.  
  37. Function EMS_OK : boolean;
  38. {Return TRUE if EMS hardware/driver functioning properly, FALSE otherwise}
  39. Begin
  40.    With Regs Do
  41.    Begin
  42.       AH := $40;
  43.       Intr($67,Regs);
  44.       EMS_Error := False;
  45.       EMS_OK := (AH = 0);
  46.    End;
  47. End;
  48.  
  49. Procedure EMS_GetPageSegment (Var PageSegment : word);
  50. {Return the EMS page mapping segment address}
  51. Begin
  52.    With Regs Do
  53.    Begin
  54.       AH := $41;
  55.       Intr($67,Regs);
  56.       PageSegment := BX;
  57.       EMS_Error := (AH <> 0);
  58.    End;
  59. End;
  60.  
  61. Procedure EMS_PageInfo (Var TotalPages, PagesAvailable : integer);
  62. {Return the total number of EMS pages, and the number of pages available}
  63. Begin
  64.    With Regs Do
  65.    Begin
  66.       AH := $42;
  67.       Intr($67,Regs);
  68.       TotalPages := DX;
  69.       PagesAvailable := BX;
  70.       EMS_Error := (AH <> 0);
  71.    End;
  72. End;
  73.  
  74. Procedure EMS_AllocatePages (PagesNeeded : word;  Var Handle : word);
  75. {Allocate the specified number of EMS pages}
  76. Begin
  77.    With Regs Do
  78.    Begin
  79.       AH := $43;
  80.       BX := PagesNeeded;
  81.       Intr($67,Regs);
  82.       Handle := DX;
  83.       EMS_Error := (AH <> 0);
  84.    End;
  85. End;
  86.  
  87. Procedure EMS_MapPage (Handle, LogicalPage : word);
  88. {Map the specified logical EMS page into the page segment}
  89. Begin
  90.    With Regs Do
  91.    Begin
  92.       AH := $44;
  93.       AL := $00;
  94.       BX := LogicalPage;
  95.       DX := Handle;
  96.       Intr($67,Regs);
  97.       EMS_Error := (AH <> 0);
  98.    End;
  99. End;
  100.  
  101. Procedure EMS_DeallocatePages (Handle : word);
  102. {Return the EMS pages allocated to this process}
  103. Begin
  104.    With Regs Do
  105.    Begin
  106.       AH := $45;
  107.       DX := Handle;
  108.       Intr($67,Regs);
  109.       EMS_Error := (AH <> 0);
  110.    End;
  111. End;
  112.  
  113. Procedure EMS_Version (Var V : string);
  114. {Return the EMS driver version (x.y)}
  115. Begin
  116.    With Regs Do
  117.    Begin
  118.       AH := $46;
  119.       Intr($67,Regs);
  120.       V := Chr((AL shr 4) + 48) + '.' + Chr((AL and $0F) + 48);
  121.       EMS_Error := (AH <> 0);
  122.    End;
  123. End;
  124.  
  125. Const
  126.    B                : array[0..3] of byte = ($00, $0F, $F0, $FF);
  127.  
  128. Var
  129.    I                ,
  130.    J                ,
  131.    K                ,
  132.    L                ,
  133.    Handle           ,
  134.    LogicalPage      ,
  135.    PageSegment      : word;
  136.    TotalPages       ,
  137.    PagesAvailable   : integer;
  138.    Version          : string[3];
  139.  
  140. Label
  141.    Exit_Proc;
  142.  
  143. Begin
  144.    ClrScr;
  145.    If EMS_Installed Then
  146.    Begin
  147.       WriteLn ('EMS installed.');
  148.       If EMS_OK Then
  149.       Begin
  150.          WriteLn ('EMS hardware working OK.');
  151.          EMS_PageInfo(TotalPages,PagesAvailable);
  152.          If EMS_Error Then
  153.          Begin
  154.             WriteLn('Error getting number of EMS pages.');
  155.             Goto Exit_Proc;
  156.          End;
  157.          WriteLn('Total EMS pages = ',TotalPages:3);
  158.          WriteLn(' Free EMS pages = ',PagesAvailable:3);
  159.          EMS_Version(Version);
  160.          If EMS_Error Then
  161.          Begin
  162.             WriteLn('Error getting EMS version.');
  163.             Goto Exit_Proc;
  164.          End;
  165.          WriteLn('EMS version is ',Version);
  166.          If PagesAvailable < 1 Then
  167.          Begin
  168.             WriteLn('Insufficient EMS pages free to run test');
  169.             Goto Exit_Proc;
  170.          End;
  171.          WriteLn('Allocating ',PagesAvailable,' pages...');
  172.          EMS_AllocatePages(PagesAvailable,Handle);
  173.          If EMS_Error Then
  174.          Begin
  175.             WriteLn('Error allocating ',PagesAvailable,' EMS pages.');
  176.             Goto Exit_Proc;
  177.          End;
  178.          EMS_GetPageSegment(PageSegment);
  179.          If EMS_Error Then
  180.          Begin
  181.             WriteLn('Error getting EMS page segment address.');
  182.             Goto Exit_Proc;
  183.          End;
  184.          For L := 1 to 4 Do
  185.          Begin
  186.             WriteLn;
  187.             WriteLn('EMS RAM test pass ',L);
  188.             For I := 0 to (PagesAvailable - 1) Do
  189.             Begin
  190.                EMS_MapPage(Handle,I);
  191.                If EMS_Error Then
  192.                Begin
  193.                   WriteLn('Error mapping handle ',Handle,' page ',I);
  194.                   Goto Exit_Proc;
  195.                End;
  196.                GotoXY(1,WhereY);
  197.                Write('Filling page ',I,' ...');
  198.                FillChar(Mem[PageSegment:0],$4000,B[(I + L) mod 4]);
  199.             End;
  200.             GotoXY(1,WhereY);  ClrEol;
  201.             WriteLn('Page filling completed.  Starting page test...');
  202.             For I := 0 to (PagesAvailable - 1) Do
  203.             Begin
  204.                EMS_MapPage(Handle,I);
  205.                If EMS_Error Then
  206.                Begin
  207.                   WriteLn('Error mapping handle ',Handle,' page ',I);
  208.                   Goto Exit_Proc;
  209.                End;
  210.                GotoXY(1,WhereY);
  211.                Write('Checking page ',I,' ...');
  212.                For K := 0 to $3FFF Do
  213.                   If Mem[PageSegment:K] <> B[(I + L) mod 4] Then
  214.                   Begin
  215.                      WriteLn('Error in EMS page ',I,' offset ',K);
  216.                      Goto Exit_Proc;
  217.                   End;
  218.             End;
  219.             GotoXY(1,WhereY);  ClrEol;
  220.             WriteLn('Page testing completed.');
  221.          End;
  222.          WriteLn('Freeing ',PagesAvailable,' pages...');
  223.          EMS_DeallocatePages(Handle);
  224.          If EMS_Error Then
  225.             WriteLn('Error deallocating EMS pages.');
  226.       End
  227.       Else
  228.          WriteLn('EMS hardware error.');
  229.    End
  230.    Else
  231.       WriteLn ('EMS not installed.');
  232. Exit_Proc:
  233.    WriteLn('EMS test completed.');
  234. End.