1 /* Catacomb Apocalypse Source Code
2 * Copyright (C) 1993-2014 Flat Rock Software
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "src/lib/16_head.h"
28 #include "src/lib/16_hc.h"
29 //#include "src/lib/modex16.h"
30 //#include "src/lib/16_ca.h"
31 //++++mh #include "src/lib/16_in.h"
33 #ifdef __DEBUG__ // 1 == Debug/Dev ; 0 == Production/final
34 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"
36 #define OUT_OF_MEM_MSG "\npee\n"
40 #define SAVENEARHEAP 0//_memavl()/4 // space to leave in data segment
41 #define SAVEFARHEAP 0//x400 // space to leave in far heap
43 #define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
53 #define EMS_STATUS 0x40
54 #define EMS_GETFRAME 0x41
55 #define EMS_GETPAGES 0x42
56 #define EMS_ALLOCPAGES 0x43
57 #define EMS_MAPPAGE 0x44
58 #define EMS_MAPXPAGE 0x50
59 #define EMS_FREEPAGES 0x45
60 #define EMS_VERSION 0x46
64 #define XMS_VERSION 0x00
66 #define XMS_ALLOCHMA 0x01
67 #define XMS_FREEHMA 0x02
69 #define XMS_GENABLEA20 0x03
70 #define XMS_GDISABLEA20 0x04
71 #define XMS_LENABLEA20 0x05
72 #define XMS_LDISABLEA20 0x06
73 #define XMS_QUERYA20 0x07
75 #define XMS_QUERYREE 0x08
76 #define XMS_ALLOC 0x09
80 #define XMS_UNLOCK 0x0D
81 #define XMS_GETINFO 0x0E
82 #define XMS_RESIZE 0x0F
84 #define XMS_ALLOCUMB 0x10
85 #define XMS_FREEUMB 0x11
87 //==========================================================================
91 dword nearheap,farheap,EMSmem,XMSmem,mainmem;
95 //==========================================================================
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
117 #define MAPPAGES 4//mm->EMSpagesmapped
119 typedef struct mmblockstruct
122 word start; dword length;
124 memptr *useptr; // pointer to the segment start
125 struct mmblockstruct huge *next;
132 boolean mmstarted, bombonerror, mmerror;
134 void __near *nearheap;
136 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
138 word numUMBs,UMBbase[MAXUMBS];
139 word endid; //end of list
140 //dword numUMBs,UMBbase[MAXUMBS];
141 mmblocktype huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;
145 =============================================================================
149 =============================================================================
154 =============================================================================
158 =============================================================================
161 //==========================================================================
163 boolean MML_CheckForEMS(void);
164 byte MML_SetupEMS(mminfo_t *mm);
165 void MML_ShutdownEMS(mminfo_t *mm);
166 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi);
167 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi);
168 boolean MML_CheckForXMS(mminfo_t *mm);
169 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
170 void MML_ShutdownXMS(mminfo_t *mm);
171 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm);
172 void MML_ClearBlock(mminfo_t *mm);
174 void MM_Startup(mminfo_t *mm, mminfotype *mmi);
175 void MM_Shutdown(mminfo_t *mm);
177 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
178 void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
179 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
180 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
181 void MM_SortMem(mminfo_t *mm);
182 void MM_ShowMemory(/*page_t *page, */mminfo_t *mm);
183 void MM_DumpData(mminfo_t *mm);
184 dword MM_UnusedMemory(mminfo_t *mm);
185 dword MM_TotalFree(mminfo_t *mm);
186 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi);
187 static void MM_EMSerr(byte *stri, byte err);
188 void MM_BombOnError(boolean bomb, mminfo_t *mm);
189 void MM_GetNewBlock(mminfo_t *mm);
190 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
192 //==========================================================================