 EMS: A unit for accessing all of the EMS 4.0 functions in Turbo Pascal.
      Written 1996 by William H. Decorie.
      Released into the public domain; modify as you wish.

 This unit supplies a Pascal interface to all of the EMS 4.0 functions,
 including the operating system functions 59xxH, 5BxxH and 5DxxH.  I use
 Turbo Pascal 6.0, but this unit should work properly with little or no
 modification with Turbo/Borland Pascal 7.0 in real mode.  Since you
 have the source right here, go ahead and change it!

 No error checking of any sort is done by this unit; garbage in will,
 at a minimum, produce garbage out and can possibly even lock up your
 computer.  This also means that no checking is performed to verify that
 the requested function is available with the currently installed EMS
 driver, or that there even is an EMS driver installed!

 At startup, this unit determines whether an EMS driver is installed,
 and stores this status in the boolean variable EMS_FLAG.  If true, it
 means that an EMS driver IS installed.  Note, once again, that even if
 this variable is false, meaning that no EMS driver is installed, all of
 the functions will still attempt to execute!

 All functions store return values in supplied variables and return the
 EMS STATUS CODE as an unsigned word value.  If the status is not OK,
 then the contents of any variable parameters is undefined.  Assume that
 all registers (except DS, SS, SP and BP of course) are destroyed.  This
 is especially important:  ES does get destroyed by most of these
 functions, so you must explicitly reload it if you use it (say, to hold
 the EMS page frame segment).

 I do not attempt to explain or spell out the EMS specification here.
 There are many other places where this can easily be found (try MS's
 internet site, for one).  The following is a short list of some books
 which I used as a reference in writing this unit:

 PC Programmer's Guide to Low-Level Functions and Interrupts
   Marcus Johnson, SAMS Publishing 1994

 The Programmer's PC Sourcebook
   Thom Hogan, Microsoft Press 1991

 Advanced Assembly Language
   Allen L. Wyatt, Sr., QUE 1992

 I do not claim responsibility for ANYTHING having to do with this code;
 use it at your own risk.  I have made an effort to make sure it does
 not have any bugs, but I'm sure you know how they can slip in.  If you
 DO find an error, by all means let me know so that I may fix it.  To be
 honest, I do not personally use most of these functions and so have not
 tested them, but they SHOULD work.

 If you are looking for a VCPI or DPMI unit, then you are not using the
 right language.  I know of no EASY way to implement VCPI or DPMI in
 Turbo Pascal 6.  I've heard that Borland Pascal 7.0 allows writing
 protected mode DOS programs, but I don't have it.

 IMPORTANT NOTE:  ALWAYS deallocate ALL memory that you allocated before
 exiting, or else that memory will NOT BE AVAILABLE UNTIL YOU REBOOT!!!!
 The exception to this is if you are running under a Protected Mode OS
 (like Windows or Win95), where that memory just isn't available under
 that particular DOS session anymore.  A simple way to check to see if
 your program is properly deallocating memory is the MEM command.  Run
 it before starting your program and record how much EMS you have, then
 run it again when your program exits; the values should be the same.
