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