]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_mm.h
mm test~
[16.git] / src / lib / 16_mm.h
1 /* Catacomb Armageddon Source Code
2  * Copyright (C) 1993-2014 Flat Rock Software
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 // ID_MM.H
20
21 #ifndef __16_EXMM__
22 #define __16_EXMM__
23
24 #include <string.h>
25 #include <malloc.h>
26 #include "src/lib/lib_head.h"
27 //++++mh        #include "src/lib/16_in.h"
28
29 //****#if 1             // 1 == Debug/Dev  ;  0 == Production/final
30 #define OUT_OF_MEM_MSG  "MM_GetPtr: Out of memory!\nYou were short :%ld bytes"
31 //****#else
32 //****#define OUT_OF_MEM_MSG    "\npee\n"
33 //****#endif
34
35
36 #define SAVENEARHEAP    0x400           // space to leave in data segment
37 #define SAVEFARHEAP             0                       // space to leave in far heap
38
39 #define BUFFERSIZE              0x1000          // miscelanious, allways available buffer
40
41 #define MAXBLOCKS               600
42
43
44 //--------
45
46 #define EMS_INT                 0x67
47
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
55
56 //--------
57
58 #define XMS_VERSION             0x00
59
60 #define XMS_ALLOCHMA    0x01
61 #define XMS_FREEHMA             0x02
62
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
68
69 #define XMS_QUERYREE    0x08
70 #define XMS_ALLOC               0x09
71 #define XMS_FREE                0x0A
72 #define XMS_MOVE                0x0B
73 #define XMS_LOCK                0x0C
74 #define XMS_UNLOCK              0x0D
75 #define XMS_GETINFO             0x0E
76 #define XMS_RESIZE              0x0F
77
78 #define XMS_ALLOCUMB    0x10
79 #define XMS_FREEUMB             0x11
80
81 //==========================================================================
82
83 typedef void /*__seg*/ * memptr;
84
85 typedef struct
86 {
87         long    nearheap,farheap,EMSmem,XMSmem,mainmem;
88 } mminfotype;
89
90 //==========================================================================
91
92 /*extern        mminfotype      mminfo;
93 extern  memptr          bufferseg;
94 extern  boolean         mmerror;
95
96 extern  void            (* beforesort) (void);
97 extern  void            (* aftersort) (void);*/
98
99 //==========================================================================
100
101 /*
102 =============================================================================
103
104                                                         LOCAL INFO
105
106 =============================================================================
107 */
108
109 #define LOCKBIT         0x80    // if set in attributes, block cannot be moved
110 #define PURGEBITS       3               // 0-3 level, 0= unpurgable, 3= purge first
111 #define PURGEMASK       0xfffc
112 #define BASEATTRIBUTES  0       // unlocked, non purgable
113
114 #define MAXUMBS         10
115
116 typedef struct mmblockstruct
117 {
118         unsigned        start,length;
119         unsigned        attributes;
120         memptr          *useptr;        // pointer to the segment start
121         struct mmblockstruct far *next;
122 } mmblocktype;
123
124
125 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!");mmfree=mmfree->next;}
126 #define GETNEWBLOCK {if(!mmfree)MML_ClearBlock();mmnew=mmfree;mmfree=mmfree->next;}
127 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=mmfree;mmfree=x;}
128
129 /*
130 =============================================================================
131
132                                                  GLOBAL VARIABLES
133
134 =============================================================================
135 */
136
137 mminfotype      mminfo;
138 memptr          bufferseg;
139 boolean         mmerror;
140
141 void            (* beforesort) (void);
142 void            (* aftersort) (void);
143
144 static  char *ParmStringsexmm[] = {"noems","noxms",""};
145
146 /*
147 =============================================================================
148
149                                                  LOCAL VARIABLES
150
151 =============================================================================
152 */
153
154 boolean         mmstarted;
155
156 void huge       *hugeheap;
157 void far        *farheap;
158 void            *nearheap;
159
160 mmblocktype     far mmblocks[MAXBLOCKS]
161                         ,far *mmhead,far *mmfree,far *mmrover,far *mmnew;
162
163 boolean         bombonerror;
164
165 unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
166
167 void            (* XMSaddr) (void);             // far pointer to XMS driver
168
169 unsigned        numUMBs,UMBbase[MAXUMBS];
170
171 //==========================================================================
172
173 void MM_Startup (void);
174 void MM_Shutdown (void);
175 void MM_MapEMS (void);
176
177 void MM_GetPtr (memptr *baseptr,dword size);
178 void MM_FreePtr (memptr *baseptr);
179
180 void MM_SetPurge (memptr *baseptr, int purge);
181 void MM_SetLock (memptr *baseptr, boolean locked);
182 void MM_SortMem (void);
183
184 void MM_ShowMemory (void);
185
186 long MM_UnusedMemory (void);
187 long MM_TotalFree (void);
188
189 void MM_BombOnError (boolean bomb);
190
191 //==========================================================================
192
193 //
194 // local prototypes
195 //
196
197 boolean         MML_CheckForEMS (void);
198 void            MML_ShutdownEMS (void);
199 void            MM_MapEMS (void);
200 boolean         MML_CheckForXMS (void);
201 void            MML_ShutdownXMS (void);
202 void            MML_UseSpace (unsigned segstart, unsigned seglength);
203 void            MML_ClearBlock (void);
204
205 int US_CheckParm(char *parm,char **strings);
206
207 //==========================================================================
208
209 #endif