]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_mm.h
fixed an issue with EMS_INT becuase i learned there is 2 wwww
[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_tail.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 dbg_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 #define EMM_INT                 0x21\r
57 \r
58 #define EMS_STATUS              0x40\r
59 #define EMS_GETFRAME    0x41\r
60 #define EMS_GETPAGES    0x42\r
61 #define EMS_ALLOCPAGES  0x43\r
62 #define EMS_MAPPAGE             0x44\r
63 #define EMS_MAPXPAGE            0x50\r
64 #define EMS_FREEPAGES   0x45\r
65 #define EMS_VERSION             0x46\r
66 \r
67 //--------\r
68 \r
69 #define XMS_INT                 0x2f\r
70 #define XMS_CALL(v)             _AH = (v);\\r
71                                                 __asm call [DWORD PTR XMSDriver]\r
72 /*__asm { mov ah,[v]\*///}\r
73 \r
74 #define XMS_VERSION             0x00\r
75 \r
76 #define XMS_ALLOCHMA            0x01\r
77 #define XMS_FREEHMA             0x02\r
78 \r
79 #define XMS_GENABLEA20  0x03\r
80 #define XMS_GDISABLEA20 0x04\r
81 #define XMS_LENABLEA20  0x05\r
82 #define XMS_LDISABLEA20 0x06\r
83 #define XMS_QUERYA20            0x07\r
84 \r
85 #define XMS_QUERYFREE   0x08\r
86 #define XMS_ALLOC               0x09\r
87 #define XMS_FREE                        0x0A\r
88 #define XMS_MOVE                        0x0B\r
89 #define XMS_LOCK                        0x0C\r
90 #define XMS_UNLOCK              0x0D\r
91 #define XMS_GETINFO             0x0E\r
92 #define XMS_RESIZE              0x0F\r
93 \r
94 #define XMS_ALLOCUMB            0x10\r
95 #define XMS_FREEUMB             0x11\r
96 \r
97 //==========================================================================\r
98 \r
99 //moved to typdefst\r
100 /*typedef struct\r
101 {\r
102         dword   nearheap,farheap,EMSmem,XMSmem,mainmem;\r
103 } mminfotype;*/\r
104 \r
105 //==========================================================================\r
106 \r
107 extern  void            (* beforesort) (void);\r
108 extern  void            (* aftersort) (void);\r
109 extern  void            (* XMSaddr) (void);             // far pointer to XMS driver\r
110 extern  dword   XMSDriver;\r
111 extern  word            XMSVer;\r
112 \r
113 //==========================================================================\r
114 \r
115 /*\r
116 =============================================================================\r
117 \r
118                                                         LOCAL INFO\r
119 \r
120 =============================================================================\r
121 */\r
122 \r
123 #define LOCKBIT         0x80    // if set in attributes, block cannot be moved\r
124 #define PURGEBITS       3               // 0-3 level, 0= unpurgable, 3= purge first\r
125 #define PURGEMASK       0xfffc\r
126 #define BASEATTRIBUTES  0       // unlocked, non purgable\r
127 \r
128 //moved to typedefst\r
129 //#define MAXUMBS               12\r
130 #define MAPPAGES                4//gvar->mm.EMSpagesmapped\r
131 \r
132 //moved to typdefst\r
133 /*typedef struct mmblockstruct\r
134 {\r
135         word    start,length;\r
136         //word  start;  dword length;\r
137         word    blob;   //for data larger than 64k\r
138         unsigned        attributes;\r
139         memptr          *useptr;        // pointer to the segment start\r
140         //huge struct mmblockstruct huge *next;\r
141         struct mmblockstruct far *next;\r
142 } mmblocktype;\r
143 \r
144 \r
145 typedef struct\r
146 {\r
147         memptr bufferseg;\r
148         boolean         mmstarted, bombonerror, mmerror;\r
149         //huge void huge        *farheap;\r
150         void far        *farheap;\r
151 #ifdef __BORLANDC__\r
152         void    *nearheap;\r
153 #endif\r
154 #ifdef __WATCOMC__\r
155         void __near     *nearheap;\r
156 #endif\r
157         //byte          EMS_status;\r
158         unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;\r
159         unsigned int EMSVer;\r
160         word numUMBs,UMBbase[MAXUMBS];\r
161         //dword numUMBs,UMBbase[MAXUMBS];\r
162         //huge mmblocktype      huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;\r
163         mmblocktype     far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;\r
164 } mminfo_t;*/\r
165 \r
166 /*\r
167 =============================================================================\r
168 \r
169                                                  GLOBAL VARIABLES\r
170 \r
171 =============================================================================\r
172 */\r
173 \r
174 \r
175 /*\r
176 =============================================================================\r
177 \r
178                                                  LOCAL VARIABLES\r
179 \r
180 =============================================================================\r
181 */\r
182 \r
183 //==========================================================================\r
184 \r
185 boolean MML_CheckForEMS(void);\r
186 //byte MML_SetupEMS(mminfo_t *mm);\r
187 //void MML_ShutdownEMS(mminfo_t *mm);\r
188 byte MM_MapEMS(global_game_variables_t *gvar);\r
189 //byte MM_MapXEMS(global_game_variables_t *gvar);\r
190 boolean MML_CheckForXMS(void);\r
191 //void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);\r
192 //void MML_ShutdownXMS(mminfo_t *mm);\r
193 void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);\r
194 void MML_ClearBlock(global_game_variables_t *gvar);\r
195 \r
196 void MM_Startup(global_game_variables_t *gvar);\r
197 void MM_Shutdown(global_game_variables_t *gvar);\r
198 \r
199 void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);\r
200 void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);\r
201 void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);\r
202 void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);\r
203 void MM_SortMem(global_game_variables_t *gvar);\r
204 void MM_ShowMemory(global_game_variables_t *gvar);\r
205 void MM_DumpData(global_game_variables_t *gvar);\r
206 dword MM_UnusedMemory(global_game_variables_t *gvar);\r
207 dword MM_TotalFree(global_game_variables_t *gvar);\r
208 void MM_Report_(global_game_variables_t *gvar);\r
209 /*static */void MM_EMSerr(byte *stri, byte err);\r
210 void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);\r
211 //void MM_GetNewBlock(mminfo_t *mm);\r
212 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);\r
213 void xms_call(byte v, global_game_variables_t *gvar);\r
214 \r
215 //==========================================================================\r
216 \r
217 #endif\r