home *** CD-ROM | disk | FTP | other *** search
- Unit EMS32;
-
- Interface
-
- Uses
- DOS;
-
- Type
- HandleRec = Record
- Handle,
- Pages : Word;
- End;
- HandleAr = Array [1..256] of HandleRec;
-
- Var
- EmmInstalled : Boolean;
- EmmMaxAvail,
- EmmTotal : Word;
- EmmSeg : Word;
- EmmVer : Byte;
-
- Procedure ReportError;
- Function EmmError : Boolean;
-
- (*********** LIM EMS 3.0 or later ***********)
- Procedure GetStatus;
- Procedure GetPageFrame ( Var pageSeg : Word );
- Procedure GetNumberOfPages ( Var total, unAlloc : Word );
- Procedure AllocateHandleAndPages ( pages : Word; Var handle : Word );
- Procedure MapPage ( physPage, logPage, handle : Word );
- Procedure ReleaseHandle ( handle : Word );
- Procedure GetVersion ( version : Byte );
- Procedure SavePageMap_30 ( handle : Word );
- Procedure RestorePageMap_30 ( handle : Word );
- Procedure GetHandleCount ( Var num : Word );
- Procedure GetHandlePages ( handle : Word; Var pages : Word );
- Procedure GetPagesForAllHandles ( Var size : Word; Var ar : HandleAr );
-
- (*********** LIM EMS 3.2 or later ***********)
- Procedure SavePageMap ( point : Pointer );
- Procedure RestorePageMap ( point : Pointer );
- Procedure Save_RestorePageMap ( srcPoint, destPoint : Pointer );
- Procedure GetSizePageMap ( size : Byte );
-
- Implementation
-
- Var
- reg : Registers;
- error : Byte;
-
- Function EmmError : Boolean;
- Begin
- EmmError := ( error <> 0 );
- End;
-
- Procedure ReportError;
- Begin
- error := reg.AH;
- If ( EMMError ) Then
- Case ( reg.AH ) Of
- $80 : WriteLn ( 'Internal EMM software error. Possible Memory Corruption');
- $81 : WriteLn ( 'Problem in EMM hardware.' );
- $82 : WriteLn ( 'EMM busy.' );
- $83 : WriteLn ( 'Invalid handle.' );
- $84 : WriteLn ( 'No such function exists.' );
- $85 : WriteLn ( 'No more handles.' );
- $86 : WriteLn ( 'Error saving/restoring mapping context.' );
- $87 : WriteLn ( 'Physically not enough pages. No pages allocated.' );
- $88 : WriteLn ( 'Not enough available pages. No pages allocated.' );
- $89 : WriteLn ( 'Can not allocate 0 pages.' );
- $8A : WriteLn ( 'Logical page is outside range of pages assigned to thishandle.' );
- $8B : WriteLn ( 'Illegal physical page number (not [0..3]).' );
- $8C : WriteLn ( 'Page mapping save area full.' );
- $8D : WriteLn ( 'Save area already contains context with this handle.' );
- $8E : WriteLn ( 'Save area does not contain context with this handle.' );
- $8F : WriteLn ( 'No such subfunction exists.' );
- End;
- End;
-
- Procedure GetStatus;
- { Return a status code indicating whether EMS and hardware are }
- { present and functional. }
- Begin
- reg.AH := $40;
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure GetPageFrame { Var pageSeg : Word };
- { This Procedure will return the segment of the Page Frame in PAGESEG }
- Begin
- reg.AH := $41;
- Intr ( $67, reg );
- PageSeg := reg.BX;
- ReportError;
- End;
-
- Procedure GetNumberOfPages { Var total, unAlloc : Word };
- { This Procedure will place the total number of EM pages in TOTAL, }
- { and the total number of unallocated pages in UNALLOC. }
- Begin
- reg.AH := $42;
- Intr ( $67, reg );
- unAlloc := reg.BX;
- total := reg.DX;
- ReportError;
- End;
-
- Procedure AllocateHandleAndPages { pages : Word; Var handle : Word };
- { This Procedure will return an EM handle in HANDLE pointing to }
- { PAGES number of logical pages. }
- Begin
- reg.AH := $43;
- reg.BX := pages;
- Intr ( $67, reg );
- handle := reg.DX;
- ReportError;
- End;
-
- Procedure MapPage { physPage, logPage, handle : Word };
- { This will map the logical page LOGPAGE in HANDLE into physical }
- { page PHYSPAGE in the page frame. }
- Begin
- reg.AH := $44;
- reg.AL := physPage;
- reg.BX := logPage;
- reg.DX := handle;
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure ReleaseHandle { handle : Word };
- { This Procedure will deallocate the EM pages assigned to HANDLE }
- { and release the handle. }
- Begin
- reg.AH := $45;
- reg.DX := handle;
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure GetVersion { version : Byte };
- { This Procedure will return the EMS version in VERSION. }
- Begin
- reg.AH := $46;
- Intr ( $67, reg );
- version := reg.AL;
- ReportError;
- End;
-
- Procedure SavePageMap_30 { handle : Word };
- { This Procedure will save the page mapping registers of the EMM }
- { hardware and associate them with the EM handle HANDLE. }
- Begin
- reg.AH := $47;
- reg.DX := handle;
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure RestorePageMap_30 { handle : Word };
- { This Procedure will restore the page mapping registers of the EMM }
- { hardware that are associated with the EM hanlde HANDLE that was }
- { saved by SavePageMap_30. }
- Begin
- reg.AH := $48;
- reg.DX := handle;
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure GetHandleCount { Var num : Word };
- { This Procedure will return the number of active EM handles in NUM. }
- Begin
- reg.AH := $4B;
- Intr ( $67, reg );
- num := reg.BX;
- ReportError;
- End;
-
- Procedure GetHandlePages { handle : Word; Var pages : Word };
- { This Procedure will return the number of EM pages allocated to HANDLE }
- { in PAGES. }
- Begin
- reg.AH := $4C;
- reg.DX := handle;
- Intr ( $67, reg );
- pages := reg.BX;
- ReportError;
- End;
-
- Procedure GetPagesForAllHandles { Var size : Word; Var ar : HandleAr };
- { This Procedure will load AR with all the active handles and the }
- { number of EM pages allocated to each. SIZE contains the number }
- { of active handles. }
- Begin
- reg.AH := $4D;
- reg.ES := Seg ( ar );
- reg.DI := Ofs ( ar );
- Intr ( $67, reg );
- size := reg.BX;
- ReportError;
- End;
-
- Procedure SavePageMap { point : Pointer };
- { This Procedure will save the page mapping information of the }
- { EM hardware into the buffer pointed to by POINT. To determine }
- { the size of POINT, use Procedure GetSizePageMap. }
- Begin
- reg.AH := $4E;
- reg.AL := $00;
- reg.ES := Seg ( point^ );
- reg.DI := Ofs ( point^ );
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure RestorePageMap { point : Pointer };
- { This Procedure will restore the page mapping information of the }
- { EM hardware that is pointed to by POINT. This information was }
- { saved by the Procedure SavePageMap. }
- Begin
- reg.AH := $4E;
- reg.AL := $01;
- reg.DS := Seg ( point^ );
- reg.SI := Ofs ( point^ );
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure Save_RestorePageMap { srcPoint, destPoint : Pointer };
- { This Procedure will save the page mapping information of the }
- { EM hardware into the buffer pointed to by DESTPOINT. Then it }
- { will load the page mapping information into the hardware from }
- { the buffer pointed to by SRCPOINT. }
- Begin
- reg.AH := $4E;
- reg.AL := $02;
- reg.DS := Seg ( srcPoint^ );
- reg.SI := Ofs ( srcPoint^ );
- reg.ES := Seg ( destPoint^ );
- reg.DI := Ofs ( destPoint^ );
- Intr ( $67, reg );
- ReportError;
- End;
-
- Procedure GetSizePageMap { size : Byte };
- { This Procedure will return the size of the buffer that is used }
- { to store the page mapping information from the hardware. }
- Begin
- reg.AH := $4E;
- reg.AL := $03;
- Intr ( $67, reg );
- size := reg.AL;
- ReportError;
- End;
-
- Type
- arType = Array [1..8] of Char;
-
- Var
- p : ^arType;
-
- Begin
- EmmInstalled := FALSE;
- GetIntVec ( $67, Pointer ( p ) );
- p := ptr ( Seg ( p^ ), $0A );
- If ( p^ = 'EMMXXXX0' ) Then
- Begin
- GetStatus;
- If ( Not EmmError ) Then
- EmmInstalled := TRUE;
-
- GetNumberOfPages ( EmmTotal, EmmMaxAvail );
- If ( EmmError ) Then
- Halt;
-
- GetPageFrame ( EmmSeg );
- If ( EmmError ) Then
- Halt;
-
- GetVersion ( EmmVer );
- If ( EmmError ) Then
- Halt;
- End;
- End.
-