]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_mm.h
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww massive work there is issue with...
[16.git] / src / lib / 16_mm.h
1 /* Catacomb Apocalypse Source Code\r
2  * Copyright (C) 1993-2014 Flat Rock Software\r
3  *\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
8  *\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
13  *\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
17  */\r
18 \r
19 // ID_MM.H\r
20 \r
21 #ifndef __16_EXMM__\r
22 #define __16_EXMM__\r
23 \r
24 #include <string.h>\r
25 #include <malloc.h>\r
26 #include "src/lib/16_head.h"\r
27 #include "src/lib/16_hc.h"\r
28 #include "src/lib/16_lib.h"\r
29 //++++mh        #include "src/lib/16_in.h"\r
30 \r
31 #ifdef __DEBUG__                // 1 == Debug/Dev  ;  0 == Production/final\r
32 #define OUT_OF_MEM_MSG  "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"\r
33 extern boolean debugpm;\r
34 #else\r
35 #define OUT_OF_MEM_MSG  "\npee\n"\r
36 #endif\r
37 \r
38 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}\r
39 #define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}\r
40 \r
41 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}\r
42 \r
43 #define SAVENEARHEAP    0x200           // space to leave in data segment\r
44 #define SAVEFARHEAP     0//x400                 // space to leave in far heap\r
45 \r
46 #define BUFFERSIZE              0x1000          // miscelanious, allways available buffer\r
47 \r
48 //moved to typdefst\r
49 //#define MAXBLOCKS             1024\r
50 \r
51 \r
52 \r
53 //--------\r
54 \r
55 #define EMS_INT                 0x67\r
56 \r
57 #define EMS_STATUS              0x40\r
58 #define EMS_GETFRAME    0x41\r
59 #define EMS_GETPAGES    0x42\r
60 #define EMS_ALLOCPAGES  0x43\r
61 #define EMS_MAPPAGE             0x44\r
62 #define EMS_MAPXPAGE            0x50\r
63 #define EMS_FREEPAGES   0x45\r
64 #define EMS_VERSION             0x46\r
65 \r
66 //--------\r
67 \r
68 #define XMS_INT                 0x2f\r
69 #define XMS_CALL(v)             _AH = (v);\\r
70                                                 __asm call [WORD PTR XMSDriver]\r
71 /*__asm { //mov (v),ah*/\r
72 \r
73 #define XMS_VERSION             0x00\r
74 \r
75 #define XMS_ALLOCHMA    0x01\r
76 #define XMS_FREEHMA             0x02\r
77 \r
78 #define XMS_GENABLEA20  0x03\r
79 #define XMS_GDISABLEA20 0x04\r
80 #define XMS_LENABLEA20  0x05\r
81 #define XMS_LDISABLEA20 0x06\r
82 #define XMS_QUERYA20    0x07\r
83 \r
84 #define XMS_QUERYFREE   0x08\r
85 #define XMS_ALLOC               0x09\r
86 #define XMS_FREE                0x0A\r
87 #define XMS_MOVE                0x0B\r
88 #define XMS_LOCK                0x0C\r
89 #define XMS_UNLOCK              0x0D\r
90 #define XMS_GETINFO             0x0E\r
91 #define XMS_RESIZE              0x0F\r
92 \r
93 #define XMS_ALLOCUMB    0x10\r
94 #define XMS_FREEUMB             0x11\r
95 \r
96 //==========================================================================\r
97 \r
98 //moved to typdefst\r
99 /*typedef struct\r
100 {\r
101         dword   nearheap,farheap,EMSmem,XMSmem,mainmem;\r
102 } mminfotype;*/\r
103 \r
104 //==========================================================================\r
105 \r
106 extern  void            (* beforesort) (void);\r
107 extern  void            (* aftersort) (void);\r
108 extern  void            (* XMSaddr) (void);             // far pointer to XMS driver\r
109 \r
110 //==========================================================================\r
111 \r
112 /*\r
113 =============================================================================\r
114 \r
115                                                         LOCAL INFO\r
116 \r
117 =============================================================================\r
118 */\r
119 \r
120 #define LOCKBIT         0x80    // if set in attributes, block cannot be moved\r
121 #define PURGEBITS       3               // 0-3 level, 0= unpurgable, 3= purge first\r
122 #define PURGEMASK       0xfffc\r
123 #define BASEATTRIBUTES  0       // unlocked, non purgable\r
124 \r
125 //moved to typedefst\r
126 //#define MAXUMBS               12\r
127 #define MAPPAGES                4//gvar->mm.EMSpagesmapped\r
128 \r
129 //moved to typdefst\r
130 /*typedef struct mmblockstruct\r
131 {\r
132         word    start,length;\r
133         //word  start;  dword length;\r
134         word    blob;   //for data larger than 64k\r
135         unsigned        attributes;\r
136         memptr          *useptr;        // pointer to the segment start\r
137         //huge struct mmblockstruct huge *next;\r
138         struct mmblockstruct far *next;\r
139 } mmblocktype;\r
140 \r
141 \r
142 typedef struct\r
143 {\r
144         memptr bufferseg;\r
145         boolean         mmstarted, bombonerror, mmerror;\r
146         //huge void huge        *farheap;\r
147         void far        *farheap;\r
148 #ifdef __BORLANDC__\r
149         void    *nearheap;\r
150 #endif\r
151 #ifdef __WATCOMC__\r
152         void __near     *nearheap;\r
153 #endif\r
154         //byte          EMS_status;\r
155         unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;\r
156         unsigned int EMSVer;\r
157         word numUMBs,UMBbase[MAXUMBS];\r
158         //dword numUMBs,UMBbase[MAXUMBS];\r
159         //huge mmblocktype      huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;\r
160         mmblocktype     far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;\r
161 } mminfo_t;*/\r
162 \r
163 /*\r
164 =============================================================================\r
165 \r
166                                                  GLOBAL VARIABLES\r
167 \r
168 =============================================================================\r
169 */\r
170 \r
171 \r
172 /*\r
173 =============================================================================\r
174 \r
175                                                  LOCAL VARIABLES\r
176 \r
177 =============================================================================\r
178 */\r
179 \r
180 //==========================================================================\r
181 \r
182 boolean MML_CheckForEMS(void);\r
183 //byte MML_SetupEMS(mminfo_t *mm);\r
184 //void MML_ShutdownEMS(mminfo_t *mm);\r
185 byte MM_MapEMS(global_game_variables_t *gvar);\r
186 byte MM_MapXEMS(global_game_variables_t *gvar);\r
187 //boolean MML_CheckForXMS(mminfo_t *mm);\r
188 //void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);\r
189 //void MML_ShutdownXMS(mminfo_t *mm);\r
190 void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);\r
191 void MML_ClearBlock(global_game_variables_t *gvar);\r
192 \r
193 void MM_Startup(global_game_variables_t *gvar);\r
194 void MM_Shutdown(global_game_variables_t *gvar);\r
195 \r
196 void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);\r
197 void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);\r
198 void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);\r
199 void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);\r
200 void MM_SortMem(global_game_variables_t *gvar);\r
201 void MM_ShowMemory(global_game_variables_t *gvar);\r
202 void MM_DumpData(global_game_variables_t *gvar);\r
203 dword MM_UnusedMemory(global_game_variables_t *gvar);\r
204 dword MM_TotalFree(global_game_variables_t *gvar);\r
205 void MM_Report_(global_game_variables_t *gvar);\r
206 /*static */void MM_EMSerr(byte *stri, byte err);\r
207 void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);\r
208 //void MM_GetNewBlock(mminfo_t *mm);\r
209 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);\r
210 \r
211 //==========================================================================\r
212 \r
213 #endif\r