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