home *** CD-ROM | disk | FTP | other *** search
- #ifndef _MEMORY_HPP
- #define _MEMORY_HPP
-
- // ------------------------------------------------------------------
- // File: MEMORY.HPP
- // Path: ...\REHACK\MEMORY\MEMORY.HPP
- // Version: 0.01
- // Author: Pat Reilly
- // CIS Id: 71333,2764
- // Created On: 6/28/93
- // Modified On:
- // Description: Memory classes for REHACK. See MEMORY.TXT for
- // more details.
- // Tabs: 4
- // ------------------------------------------------------------------
-
- // Bring in general typedefs/enums.
- #ifndef _TYPES_HPP
- #include "..\GENERAL\TYPES.HPP"
- #endif
-
- const word
- EmsPagesPerFrame = 4U,
- EmsMaxBlkSize = 0xFFFFU,
- EmsPageSize = 16384U,
- XmsMaxBlkSize = 0xFFF0U;
-
- // Memory types: conventional, EMS, disk
- enum MemType { MemUnknown, MemConv, MemEMS, MemDisk, MemXMS };
-
- // Class MemoryObject
- // Base class
- // All memory types are derived from MemoryObject.
-
- class MemoryObject
- {
- public:
-
- MemoryObject();
- virtual ~MemoryObject();
-
- virtual MemType type();
- virtual bool allocate(word) = 0;
- virtual void free() = 0;
- virtual void FAR* lock() = 0;
- virtual void unlock() = 0;
- virtual long memAvail() = 0;
- virtual long maxAvail() = 0;
- word memSize();
-
- protected:
-
- word memsize;
- word lockflag;
- };
-
- inline MemoryObject::MemoryObject()
- {
- memsize = 0;
- lockflag = 0;
- }
-
- inline MemoryObject::~MemoryObject()
- {
- free();
- }
-
- inline MemType MemoryObject::type()
- {
- return MemUnknown;
- }
-
- inline word MemoryObject::memSize()
- {
- return memsize;
- }
-
- // Class ConvMemory
- // Derived from: MemoryObject
-
- class ConvMemory : public MemoryObject
- {
- public:
-
- ConvMemory();
- ConvMemory(word);
-
- virtual MemType type();
- virtual bool allocate(word);
- virtual void free();
- virtual void FAR* lock();
- virtual void unlock();
- virtual long memAvail();
- virtual long maxAvail();
-
- static long memPoolSize;
-
- protected:
-
- void far *vp;
- };
-
- inline MemType ConvMemory::type()
- {
- return MemConv;
- }
-
- // Class EmsMemory
- // Derived from: MemoryObject
-
- class EmsMemory : public MemoryObject
- {
- public:
-
- EmsMemory();
- EmsMemory(word);
-
- virtual MemType type();
- virtual bool allocate(word);
- virtual void free();
- virtual void FAR* lock();
- virtual void unlock();
-
- virtual long memAvail();
- virtual long maxAvail();
-
- friend void ClearEms();
-
- protected:
-
- static word handle;
- static bool isInitialized;
- static EmsMemory* head;
- static long lastAddr;
- static bool framePageInUse[EmsPagesPerFrame];
- static word frameSeg;
-
- EmsMemory* next;
- long addr;
- int framePage;
-
- void init();
- static bool fitsInto(long addr, long next, word sz);
- static long nextPageAddr(long addr);
- static word pageOf(long addr);
- static long pageAddr(word page);
- static int availableFramePage(word count);
- static void mapPagesToFrame(int st, word page, word count);
- static void FAR* framePageAddr(int page);
- static void unmapFramePages(int st, word count);
- };
-
- inline MemType EmsMemory::type()
- {
- return MemEMS;
- }
-
- // Class XmsMemory
- // Derived from: MemoryObject
-
- class XmsMemory : public MemoryObject
- {
- public:
-
- XmsMemory();
- XmsMemory(word);
-
- virtual MemType type();
- virtual bool allocate(word);
- virtual void free();
- virtual void FAR* lock();
- virtual void unlock();
-
- virtual long memAvail();
- virtual long maxAvail();
-
- friend void ClearXms();
- friend class UmbMemory;
-
- protected:
-
- static word handle;
- static bool isInitialized;
- static XmsMemory* head;
- static long lastAddr;
- static dword fnAddr;
- MemoryObject* frame;
- void FAR* frameBuf;
-
- static word allocUmb(word);
- static void freeUmb(word);
-
- XmsMemory* next;
- long addr;
-
- void init();
- static bool fitsInto(long addr, long next, word sz);
- };
-
- inline MemType XmsMemory::type()
- {
- return MemXMS;
- }
-
- // Class DiskMemory
- // Derived from: MemoryObject
-
- class DiskMemory : public MemoryObject
- {
- public:
-
- DiskMemory();
- DiskMemory(word);
-
- virtual MemType type();
- virtual bool allocate(word);
- virtual void free();
- virtual void FAR* lock();
- virtual void unlock();
- virtual long memAvail();
- virtual long maxAvail();
-
- friend void ClearDisk();
-
- protected:
-
- static int handle;
- static bool isInitialized;
- static DiskMemory* head;
- static long lastAddr;
-
- MemoryObject* frame;
- void FAR* frameBuf;
- DiskMemory* next;
- long addr;
-
- void init();
- static bool fitsInto(long addr, long next, word sz);
- };
-
- inline MemType DiskMemory::type()
- {
- return MemDisk;
- }
-
- // Class VMemManager
-
- class VMemManager
- {
- public:
-
- static MemoryObject* allocate(word);
- static MemType allocScheme[5];
- };
-
- #endif // _MEMORY_HPP
-