#if !defined(XMSMGR)
#define XMSMGR

#if !defined (VMSMGR)
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include <alloc.h>
#endif

typedef struct	{
	unsigned long emb_length;
	unsigned source_handle;
	unsigned long source_offset;
	unsigned dest_handle;
	unsigned long dest_offset;
} xmsparms;

typedef int Boolean;
#define FALSE	0
#define TRUE	1

class xmsmgr	{
	enum xms_err	{	notimpl 	= 0x80,
				vdisk		= 0x81,
				a20err		= 0x82,
				generr		= 0x8e,
				unrecov		= 0x8f,
				nohma		= 0x90,
				hmainuse	= 0x91,
				hmamin		= 0x92,
				hmanotal	= 0x93,
				a20enab		= 0x94,
				allxms		= 0xa0,
				emmhandl	= 0xa1,
				invhandl	= 0xa2,
				srchandl	= 0xa3,
				srcoffs		= 0xa4,
				dsthandl	= 0xa5,
				dstoffs		= 0xa6,
				invlen		= 0xa7,
				overlap		= 0xa8,
				parity		= 0xa9,
				notlock		= 0xaa,
				islock		= 0xab,
				lockcnt		= 0xac,
				lockfail	= 0xad,
				smallumb	= 0xb0,
				noumb		= 0xb1,
				umbseg		= 0xb2,
				xmshandl	= 0xff
	};
	long xmsaddr;
	unsigned largest_free_xm;
	unsigned total_free_xm;
	Boolean installed;
	unsigned char errcode;
	unsigned (*list_handles)[128][2];
public:
	xmsmgr();
	~xmsmgr();
	inline operator void*() { return (void *)installed; }
	inline int operator!() { return !installed; }
	inline int is_installed() { return installed; }
	void query_xms();
	inline unsigned query_largest_free_xm() { return largest_free_xm; }
	inline unsigned query_total_free_xm() { return total_free_xm; }
	inline unsigned char readerr() { return errcode; }
	inline void clearerr() { installed = TRUE; errcode = 0; }
	char* xmserr();
	int alloc_emb( size_t kbytes );
	void free_emb( int listnum );
	Boolean stow( char far* send, size_t listnum,
		unsigned long bytes, unsigned long ofs );
	Boolean fetch( char far* receive, size_t listnum,
		unsigned long bytes, unsigned long ofs );
};

#endif

	
