home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1101.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-11-17  |  8.0 KB  |  287 lines

  1. Unit EMS32;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   DOS;
  7.  
  8. Type
  9.   HandleRec = Record
  10.                 Handle,
  11.                 Pages : Word;
  12.               End;
  13.   HandleAr = Array [1..256] of HandleRec;
  14.  
  15. Var
  16.   EmmInstalled : Boolean;
  17.   EmmMaxAvail,
  18.   EmmTotal     : Word;
  19.   EmmSeg       : Word;
  20.   EmmVer       : Byte;
  21.  
  22. Procedure ReportError;
  23. Function EmmError : Boolean;
  24.  
  25. (*********** LIM EMS 3.0 or later ***********)
  26. Procedure GetStatus;
  27. Procedure GetPageFrame ( Var pageSeg : Word );
  28. Procedure GetNumberOfPages ( Var total, unAlloc : Word );
  29. Procedure AllocateHandleAndPages ( pages : Word; Var handle : Word );
  30. Procedure MapPage ( physPage, logPage, handle : Word );
  31. Procedure ReleaseHandle ( handle : Word );
  32. Procedure GetVersion ( version : Byte );
  33. Procedure SavePageMap_30 ( handle : Word );
  34. Procedure RestorePageMap_30 ( handle : Word );
  35. Procedure GetHandleCount ( Var num : Word );
  36. Procedure GetHandlePages ( handle : Word; Var pages : Word );
  37. Procedure GetPagesForAllHandles ( Var size : Word; Var ar : HandleAr );
  38.  
  39. (*********** LIM EMS 3.2 or later ***********)
  40. Procedure SavePageMap ( point : Pointer );
  41. Procedure RestorePageMap ( point : Pointer );
  42. Procedure Save_RestorePageMap ( srcPoint, destPoint : Pointer );
  43. Procedure GetSizePageMap ( size : Byte );
  44.  
  45. Implementation
  46.  
  47. Var
  48.   reg   : Registers;
  49.   error : Byte;
  50.  
  51. Function EmmError : Boolean;
  52. Begin
  53.   EmmError := ( error <> 0 );
  54. End;
  55.  
  56. Procedure ReportError;
  57. Begin
  58.   error := reg.AH;
  59.   If ( EMMError ) Then
  60.     Case ( reg.AH ) Of
  61.       $80 : WriteLn ( 'Internal EMM software error. Possible Memory Corruption');
  62.       $81 : WriteLn ( 'Problem in EMM hardware.' );
  63.       $82 : WriteLn ( 'EMM busy.' );
  64.       $83 : WriteLn ( 'Invalid handle.' );
  65.       $84 : WriteLn ( 'No such function exists.' );
  66.       $85 : WriteLn ( 'No more handles.' );
  67.       $86 : WriteLn ( 'Error saving/restoring mapping context.' );
  68.       $87 : WriteLn ( 'Physically not enough pages. No pages allocated.' );
  69.       $88 : WriteLn ( 'Not enough available pages. No pages allocated.' );
  70.       $89 : WriteLn ( 'Can not allocate 0 pages.' );
  71.       $8A : WriteLn ( 'Logical page is outside range of pages assigned to thishandle.' );
  72.       $8B : WriteLn ( 'Illegal physical page number (not [0..3]).' );
  73.       $8C : WriteLn ( 'Page mapping save area full.' );
  74.       $8D : WriteLn ( 'Save area already contains context with this handle.' );
  75.       $8E : WriteLn ( 'Save area does not contain context with this handle.' );
  76.       $8F : WriteLn ( 'No such subfunction exists.' );
  77.     End;
  78. End;
  79.  
  80. Procedure GetStatus;
  81. { Return a status code indicating whether EMS and hardware are }
  82. { present and functional.                                      }
  83. Begin
  84.   reg.AH := $40;
  85.   Intr ( $67, reg );
  86.   ReportError;
  87. End;
  88.  
  89. Procedure GetPageFrame { Var pageSeg : Word };
  90. { This Procedure will return the segment of the Page Frame in PAGESEG }
  91. Begin
  92.   reg.AH := $41;
  93.   Intr ( $67, reg );
  94.   PageSeg := reg.BX;
  95.   ReportError;
  96. End;
  97.  
  98. Procedure GetNumberOfPages { Var total, unAlloc : Word };
  99. { This Procedure will place the total number of EM pages in TOTAL, }
  100. { and the total number of unallocated pages in UNALLOC.           }
  101. Begin
  102.   reg.AH := $42;
  103.   Intr ( $67, reg );
  104.   unAlloc := reg.BX;
  105.   total := reg.DX;
  106.   ReportError;
  107. End;
  108.  
  109. Procedure AllocateHandleAndPages { pages : Word; Var handle : Word };
  110. { This Procedure will return an EM handle in HANDLE pointing to }
  111. { PAGES number of logical pages.                               }
  112. Begin
  113.   reg.AH := $43;
  114.   reg.BX := pages;
  115.   Intr ( $67, reg );
  116.   handle := reg.DX;
  117.   ReportError;
  118. End;
  119.  
  120. Procedure MapPage { physPage, logPage, handle : Word };
  121. { This will map the logical page LOGPAGE in HANDLE into physical }
  122. { page PHYSPAGE in the page frame.                               }
  123. Begin
  124.   reg.AH := $44;
  125.   reg.AL := physPage;
  126.   reg.BX := logPage;
  127.   reg.DX := handle;
  128.   Intr ( $67, reg );
  129.   ReportError;
  130. End;
  131.  
  132. Procedure ReleaseHandle { handle : Word };
  133. { This Procedure will deallocate the EM pages assigned to HANDLE }
  134. { and release the handle.                                       }
  135. Begin
  136.   reg.AH := $45;
  137.   reg.DX := handle;
  138.   Intr ( $67, reg );
  139.   ReportError;
  140. End;
  141.  
  142. Procedure GetVersion { version : Byte };
  143. { This Procedure will return the EMS version in VERSION. }
  144. Begin
  145.   reg.AH := $46;
  146.   Intr ( $67, reg );
  147.   version := reg.AL;
  148.   ReportError;
  149. End;
  150.  
  151. Procedure SavePageMap_30 { handle : Word };
  152. { This Procedure will save the page mapping registers of the EMM }
  153. { hardware and associate them with the EM handle HANDLE.        }
  154. Begin
  155.   reg.AH := $47;
  156.   reg.DX := handle;
  157.   Intr ( $67, reg );
  158.   ReportError;
  159. End;
  160.  
  161. Procedure RestorePageMap_30 { handle : Word };
  162. { This Procedure will restore the page mapping registers of the EMM }
  163. { hardware that are associated with the EM hanlde HANDLE that was  }
  164. { saved by SavePageMap_30.                                         }
  165. Begin
  166.   reg.AH := $48;
  167.   reg.DX := handle;
  168.   Intr ( $67, reg );
  169.   ReportError;
  170. End;
  171.  
  172. Procedure GetHandleCount { Var num : Word };
  173. { This Procedure will return the number of active EM handles in NUM. }
  174. Begin
  175.   reg.AH := $4B;
  176.   Intr ( $67, reg );
  177.   num := reg.BX;
  178.   ReportError;
  179. End;
  180.  
  181. Procedure GetHandlePages { handle : Word; Var pages : Word };
  182. { This Procedure will return the number of EM pages allocated to HANDLE }
  183. { in PAGES.                                                            }
  184. Begin
  185.   reg.AH := $4C;
  186.   reg.DX := handle;
  187.   Intr ( $67, reg );
  188.   pages := reg.BX;
  189.   ReportError;
  190. End;
  191.  
  192. Procedure GetPagesForAllHandles { Var size : Word; Var ar : HandleAr };
  193. { This Procedure will load AR with all the active handles and the }
  194. { number of EM pages allocated to each. SIZE contains the number }
  195. { of active handles.                                             }
  196. Begin
  197.   reg.AH := $4D;
  198.   reg.ES := Seg ( ar );
  199.   reg.DI := Ofs ( ar );
  200.   Intr ( $67, reg );
  201.   size := reg.BX;
  202.   ReportError;
  203. End;
  204.  
  205. Procedure SavePageMap { point : Pointer };
  206. { This Procedure will save the page mapping information of the   }
  207. { EM hardware into the buffer pointed to by POINT. To determine }
  208. { the size of POINT, use Procedure GetSizePageMap.               }
  209. Begin
  210.   reg.AH := $4E;
  211.   reg.AL := $00;
  212.   reg.ES := Seg ( point^ );
  213.   reg.DI := Ofs ( point^ );
  214.   Intr ( $67, reg );
  215.   ReportError;
  216. End;
  217.  
  218. Procedure RestorePageMap { point : Pointer };
  219. { This Procedure will restore the page mapping information of the }
  220. { EM hardware that is pointed to by POINT. This information was  }
  221. { saved by the Procedure SavePageMap.                             }
  222. Begin
  223.   reg.AH := $4E;
  224.   reg.AL := $01;
  225.   reg.DS := Seg ( point^ );
  226.   reg.SI := Ofs ( point^ );
  227.   Intr ( $67, reg );
  228.   ReportError;
  229. End;
  230.  
  231. Procedure Save_RestorePageMap { srcPoint, destPoint : Pointer };
  232. { This Procedure will save the page mapping information of the   }
  233. { EM hardware into the buffer pointed to by DESTPOINT. Then it  }
  234. { will load the page mapping information into the hardware from }
  235. { the buffer pointed to by SRCPOINT.                            }
  236. Begin
  237.   reg.AH := $4E;
  238.   reg.AL := $02;
  239.   reg.DS := Seg ( srcPoint^ );
  240.   reg.SI := Ofs ( srcPoint^ );
  241.   reg.ES := Seg ( destPoint^ );
  242.   reg.DI := Ofs ( destPoint^ );
  243.   Intr ( $67, reg );
  244.   ReportError;
  245. End;
  246.  
  247. Procedure GetSizePageMap { size : Byte };
  248. { This Procedure will return the size of the buffer that is used }
  249. { to store the page mapping information from the hardware.      }
  250. Begin
  251.   reg.AH := $4E;
  252.   reg.AL := $03;
  253.   Intr ( $67, reg );
  254.   size := reg.AL;
  255.   ReportError;
  256. End;
  257.  
  258. Type
  259.   arType = Array [1..8] of Char;
  260.  
  261. Var
  262.   p : ^arType;
  263.  
  264. Begin
  265.   EmmInstalled := FALSE;
  266.   GetIntVec ( $67, Pointer ( p ) );
  267.   p := ptr ( Seg ( p^ ), $0A );
  268.   If ( p^ = 'EMMXXXX0' ) Then
  269.   Begin
  270.     GetStatus;
  271.     If ( Not EmmError ) Then
  272.       EmmInstalled := TRUE;
  273.  
  274.     GetNumberOfPages ( EmmTotal, EmmMaxAvail );
  275.     If ( EmmError ) Then
  276.       Halt;
  277.  
  278.     GetPageFrame ( EmmSeg );
  279.     If ( EmmError ) Then
  280.       Halt;
  281.  
  282.     GetVersion ( EmmVer );
  283.     If ( EmmError ) Then
  284.       Halt;
  285.   End;
  286. End.
  287.