1 /* Catacomb Apocalypse Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\r
4 * This program is free software; you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation; either version 2 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License along
\r
15 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 #include "src/lib/16_head.h"
27 //++++mh #include "src/lib/16_in.h"
29 #ifdef __DEBUG__ // 1 == Debug/Dev ; 0 == Production/final
30 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%ld bytes"
32 #define OUT_OF_MEM_MSG "\npee\n"
36 #define SAVENEARHEAP 0x400 // space to leave in data segment
37 #define SAVEFARHEAP 0 // space to leave in far heap
39 #define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
48 #define EMS_STATUS 0x40
49 #define EMS_GETFRAME 0x41
50 #define EMS_GETPAGES 0x42
51 #define EMS_ALLOCPAGES 0x43
52 #define EMS_MAPPAGE 0x44
53 #define EMS_FREEPAGES 0x45
54 #define EMS_VERSION 0x46
58 #define XMS_VERSION 0x00
60 #define XMS_ALLOCHMA 0x01
61 #define XMS_FREEHMA 0x02
63 #define XMS_GENABLEA20 0x03
64 #define XMS_GDISABLEA20 0x04
65 #define XMS_LENABLEA20 0x05
66 #define XMS_LDISABLEA20 0x06
67 #define XMS_QUERYA20 0x07
69 #define XMS_QUERYREE 0x08
70 #define XMS_ALLOC 0x09
74 #define XMS_UNLOCK 0x0D
75 #define XMS_GETINFO 0x0E
76 #define XMS_RESIZE 0x0F
78 #define XMS_ALLOCUMB 0x10
79 #define XMS_FREEUMB 0x11
81 //==========================================================================
82 //I hope this is correct!
84 typedef void __based(__self) * memptr; //__based(seg) * memptr;
88 dword nearheap,farheap/*,hugeheap*/,EMSmem,XMSmem,mainmem;
91 //==========================================================================
93 /*extern mminfotype mminfo;
94 extern memptr bufferseg;
95 extern boolean mmerror;*/
97 extern void (* beforesort) (void);
98 extern void (* aftersort) (void);
99 extern void (* XMSaddr) (void); // far pointer to XMS driver
101 //==========================================================================
104 =============================================================================
108 =============================================================================
111 #define LOCKBIT 0x80 // if set in attributes, block cannot be moved
112 #define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
113 #define PURGEMASK 0xfffc
114 #define BASEATTRIBUTES 0 // unlocked, non purgable
118 typedef struct mmblockstruct
120 unsigned start,length;
122 memptr *useptr; // pointer to the segment start
123 struct mmblockstruct far *next;
130 boolean mmstarted, bombonerror, mmerror;
131 //void huge *hugeheap;
132 void huge/*far*/ *farheap;
\r
134 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
136 unsigned numUMBs,UMBbase[MAXUMBS];
137 mmblocktype huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;
141 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!");mmfree=mmfree->next;}
142 //#define GETNEWBLOCK {if(!mmfree)MML_ClearBlock();mmnew=mmfree;mmfree=mmfree->next;}
143 //#define FREEBLOCK(x) {*x->useptr=NULL;x->next=mmfree;mmfree=x;}
146 =============================================================================
150 =============================================================================
153 /*static mminfotype mminfo;
154 static memptr bufferseg;
156 static void (* beforesort) (void);
157 static void (* aftersort) (void);*/
160 =============================================================================
164 =============================================================================
167 /*static void huge *hugeheap;
168 static void far *farheap;
169 static void *nearheap;
171 static mmblocktype far mmblocks[MAXBLOCKS]
172 ,far *mmhead,far *mmfree,far *mmrover,far *mmnew;
175 static unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
176 static unsigned int EMSVer;
178 static void (* XMSaddr) (void); // far pointer to XMS driver
180 static unsigned numUMBs,UMBbase[MAXUMBS];*/
182 //==========================================================================
184 boolean MML_CheckForEMS(void);
\r
185 unsigned MML_SetupEMS(mminfo_t *mm);
\r
186 void MML_ShutdownEMS(mminfo_t *mm);
\r
187 unsigned MM_MapEMS(mminfo_t *mm);
\r
188 boolean MML_CheckForXMS(mminfo_t *mm);
\r
189 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
190 void MML_ShutdownXMS(mminfo_t *mm);
\r
191 void MML_UseSpace(unsigned segstart, unsigned seglength, mminfo_t *mm);
\r
192 void MML_ClearBlock(mminfo_t *mm);
194 void MM_Startup(mminfo_t *mm, mminfotype *mmi);
\r
195 void MM_Shutdown(mminfo_t *mm);
197 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
\r
198 void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
\r
199 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
\r
200 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
\r
201 void MM_SortMem(mminfo_t *mm);
\r
202 void MM_ShowMemory(mminfo_t *mm);
\r
203 dword MM_UnusedMemory(mminfo_t *mm);
\r
204 dword MM_TotalFree(mminfo_t *mm);
\r
205 void MM_Report(mminfo_t *mm, mminfotype *mmi);
\r
206 int MM_EMSVer(void);
\r
207 void MM_BombOnError(boolean bomb, mminfo_t *mm);
208 void MM_GetNewBlock(mminfo_t *mm);
209 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
211 //==========================================================================