home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / memory / memory.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  4.6 KB  |  257 lines

  1. #ifndef _MEMORY_HPP
  2. #define _MEMORY_HPP
  3.  
  4. // ------------------------------------------------------------------
  5. // File:        MEMORY.HPP
  6. // Path:        ...\REHACK\MEMORY\MEMORY.HPP
  7. // Version:        0.01
  8. // Author:        Pat Reilly
  9. // CIS Id:        71333,2764
  10. // Created On:    6/28/93
  11. // Modified On:
  12. // Description:    Memory classes for REHACK. See MEMORY.TXT for
  13. //                more details.
  14. // Tabs:        4
  15. // ------------------------------------------------------------------
  16.  
  17. // Bring in general typedefs/enums.
  18. #ifndef _TYPES_HPP
  19. #include "..\GENERAL\TYPES.HPP"
  20. #endif
  21.  
  22. const word
  23.     EmsPagesPerFrame     = 4U,
  24.     EmsMaxBlkSize        = 0xFFFFU,
  25.     EmsPageSize            = 16384U,
  26.     XmsMaxBlkSize        = 0xFFF0U;
  27.  
  28. // Memory types: conventional, EMS, disk
  29. enum MemType { MemUnknown, MemConv, MemEMS, MemDisk, MemXMS };
  30.  
  31. // Class MemoryObject
  32. // Base class
  33. //    All memory types are derived from MemoryObject.
  34.  
  35. class MemoryObject
  36. {
  37. public:
  38.  
  39.     MemoryObject();
  40.     virtual ~MemoryObject();
  41.  
  42.     virtual MemType type();
  43.     virtual bool allocate(word) = 0;
  44.     virtual void free() = 0;
  45.     virtual void FAR* lock() = 0;
  46.     virtual void unlock() = 0;
  47.     virtual long memAvail() = 0;
  48.     virtual long maxAvail() = 0;
  49.     word memSize();
  50.  
  51. protected:
  52.  
  53.     word memsize;
  54.     word lockflag;
  55. };
  56.  
  57. inline MemoryObject::MemoryObject()
  58. {
  59.     memsize = 0;
  60.     lockflag = 0;
  61. }
  62.  
  63. inline MemoryObject::~MemoryObject()
  64. {
  65.     free();
  66. }
  67.  
  68. inline MemType MemoryObject::type()
  69. {
  70.     return MemUnknown;
  71. }
  72.  
  73. inline word MemoryObject::memSize()
  74. {
  75.     return memsize;
  76. }
  77.  
  78. // Class ConvMemory
  79. // Derived from: MemoryObject
  80.  
  81. class ConvMemory : public MemoryObject
  82. {
  83. public:
  84.  
  85.     ConvMemory();
  86.     ConvMemory(word);
  87.  
  88.     virtual MemType type();
  89.     virtual bool allocate(word);
  90.     virtual void free();
  91.     virtual void FAR* lock();
  92.     virtual void unlock();
  93.     virtual long memAvail();
  94.     virtual long maxAvail();
  95.  
  96.     static long memPoolSize;
  97.  
  98. protected:
  99.  
  100.     void far *vp;
  101. };
  102.  
  103. inline MemType ConvMemory::type()
  104. {
  105.     return MemConv;
  106. }
  107.  
  108. // Class EmsMemory
  109. // Derived from: MemoryObject
  110.  
  111. class EmsMemory : public MemoryObject
  112. {
  113. public:
  114.  
  115.     EmsMemory();
  116.     EmsMemory(word);
  117.  
  118.     virtual MemType type();
  119.     virtual bool allocate(word);
  120.     virtual void free();
  121.     virtual void FAR* lock();
  122.     virtual void unlock();
  123.  
  124.     virtual long memAvail();
  125.     virtual long maxAvail();
  126.  
  127.     friend void ClearEms();
  128.  
  129. protected:
  130.  
  131.     static word handle;
  132.     static bool isInitialized;
  133.     static EmsMemory* head;
  134.     static long lastAddr;
  135.     static bool framePageInUse[EmsPagesPerFrame];
  136.     static word frameSeg;
  137.  
  138.     EmsMemory* next;
  139.     long addr;
  140.     int framePage;
  141.  
  142.     void init();
  143.     static bool fitsInto(long addr, long next, word sz);
  144.     static long nextPageAddr(long addr);
  145.     static word pageOf(long addr);
  146.     static long pageAddr(word page);
  147.     static int availableFramePage(word count);
  148.     static void mapPagesToFrame(int st, word page, word count);
  149.     static void FAR* framePageAddr(int page);
  150.     static void unmapFramePages(int st, word count);
  151. };
  152.  
  153. inline MemType EmsMemory::type()
  154. {
  155.     return MemEMS;
  156. }
  157.  
  158. // Class XmsMemory
  159. // Derived from: MemoryObject
  160.  
  161. class XmsMemory : public MemoryObject
  162. {
  163. public:
  164.  
  165.     XmsMemory();
  166.     XmsMemory(word);
  167.  
  168.     virtual MemType type();
  169.     virtual bool allocate(word);
  170.     virtual void free();
  171.     virtual void FAR* lock();
  172.     virtual void unlock();
  173.  
  174.     virtual long memAvail();
  175.     virtual long maxAvail();
  176.  
  177.     friend void ClearXms();
  178.     friend class UmbMemory;
  179.  
  180. protected:
  181.  
  182.     static word handle;
  183.     static bool isInitialized;
  184.     static XmsMemory* head;
  185.     static long lastAddr;
  186.     static dword fnAddr;
  187.     MemoryObject* frame;
  188.     void FAR* frameBuf;
  189.  
  190.     static word allocUmb(word);
  191.     static void freeUmb(word);
  192.  
  193.     XmsMemory* next;
  194.     long addr;
  195.  
  196.     void init();
  197.     static bool fitsInto(long addr, long next, word sz);
  198. };
  199.  
  200. inline MemType XmsMemory::type()
  201. {
  202.     return MemXMS;
  203. }
  204.  
  205. // Class DiskMemory
  206. // Derived from: MemoryObject
  207.  
  208. class DiskMemory : public MemoryObject
  209. {
  210. public:
  211.  
  212.     DiskMemory();
  213.     DiskMemory(word);
  214.  
  215.     virtual MemType type();
  216.     virtual bool allocate(word);
  217.     virtual void free();
  218.     virtual void FAR* lock();
  219.     virtual void unlock();
  220.     virtual long memAvail();
  221.     virtual long maxAvail();
  222.  
  223.     friend void ClearDisk();
  224.  
  225. protected:
  226.  
  227.     static int handle;
  228.     static bool isInitialized;
  229.     static DiskMemory* head;
  230.     static long lastAddr;
  231.  
  232.     MemoryObject* frame;
  233.     void FAR* frameBuf;
  234.     DiskMemory* next;
  235.     long addr;
  236.  
  237.     void init();
  238.     static bool fitsInto(long addr, long next, word sz);
  239. };
  240.  
  241. inline MemType DiskMemory::type()
  242. {
  243.     return MemDisk;
  244. }
  245.  
  246. // Class VMemManager
  247.  
  248. class VMemManager
  249. {
  250. public:
  251.  
  252.     static MemoryObject* allocate(word);
  253.     static MemType allocScheme[5];
  254. };
  255.  
  256. #endif    // _MEMORY_HPP
  257.