]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_mm.h
omg so many bugs!!!
[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 <bios.h>
27 #include "src/lib/16_head.h"
28 //++++mh        #include "src/lib/16_in.h"
29
30 #ifdef __DEBUG__                // 1 == Debug/Dev  ;  0 == Production/final
31 #define OUT_OF_MEM_MSG  "MM_GetPtr: Out of memory!\nYou were short :%ld bytes"
32 #else
33 #define OUT_OF_MEM_MSG  "\npee\n"
34 #endif
35
36
37 #define SAVENEARHEAP    0x200           // space to leave in data segment
38 #define SAVEFARHEAP             0                       // space to leave in far heap
39
40 #define BUFFERSIZE              0x1000          // miscelanious, allways available buffer
41
42 #define MAXBLOCKS               600
43
44
45 //--------
46
47 #define EMS_INT                 0x67
48
49 #define EMS_STATUS              0x40
50 #define EMS_GETFRAME    0x41
51 #define EMS_GETPAGES    0x42
52 #define EMS_ALLOCPAGES  0x43
53 #define EMS_MAPPAGE             0x44
54 #define EMS_FREEPAGES   0x45
55 #define EMS_VERSION             0x46
56
57 //--------
58
59 #define XMS_VERSION             0x00
60
61 #define XMS_ALLOCHMA    0x01
62 #define XMS_FREEHMA             0x02
63
64 #define XMS_GENABLEA20  0x03
65 #define XMS_GDISABLEA20 0x04
66 #define XMS_LENABLEA20  0x05
67 #define XMS_LDISABLEA20 0x06
68 #define XMS_QUERYA20    0x07
69
70 #define XMS_QUERYREE    0x08
71 #define XMS_ALLOC               0x09
72 #define XMS_FREE                0x0A
73 #define XMS_MOVE                0x0B
74 #define XMS_LOCK                0x0C
75 #define XMS_UNLOCK              0x0D
76 #define XMS_GETINFO             0x0E
77 #define XMS_RESIZE              0x0F
78
79 #define XMS_ALLOCUMB    0x10
80 #define XMS_FREEUMB             0x11
81
82 //==========================================================================
83 //I hope this is correct!
84 //__segment                seg;
85 typedef void __based(__self) * memptr; //__based(seg) * memptr;
86
87 typedef struct
88 {
89         dword   nearheap,farheap,EMSmem,XMSmem,mainmem;
90 } mminfotype;
91
92 //==========================================================================
93
94 extern  void            (* beforesort) (void);
95 extern  void            (* aftersort) (void);
96 extern void             (* XMSaddr) (void);             // far pointer to XMS driver
97
98 //==========================================================================
99
100 /*
101 =============================================================================
102
103                                                         LOCAL INFO
104
105 =============================================================================
106 */
107
108 #define LOCKBIT         0x80    // if set in attributes, block cannot be moved
109 #define PURGEBITS       3               // 0-3 level, 0= unpurgable, 3= purge first
110 #define PURGEMASK       0xfffc
111 #define BASEATTRIBUTES  0       // unlocked, non purgable
112
113 #define MAXUMBS         12
114
115 typedef struct mmblockstruct
116 {
117         word    start,length;
118         //dword start,length;
119         //word  start;
120         //dword length;
121         //++++word sega;                                //how many 64kb segment blocks it takes up if there is many data!
122         unsigned        attributes;
123         memptr          *useptr;        // pointer to the segment start
124         struct mmblockstruct huge *next;
125 } mmblocktype;
126
127
128 typedef struct
129 {
130         memptr bufferseg;
131         boolean         mmstarted, bombonerror, mmerror;
132         void huge       *farheap;
133         void            *nearheap;
134         unsigned        totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
135         unsigned int EMSVer;
136         word numUMBs,UMBbase[MAXUMBS];
137         //dword numUMBs,UMBbase[MAXUMBS];
138         mmblocktype     huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;
139 } mminfo_t;
140
141 /*
142 =============================================================================
143
144                                                  GLOBAL VARIABLES
145
146 =============================================================================
147 */
148
149
150 /*
151 =============================================================================
152
153                                                  LOCAL VARIABLES
154
155 =============================================================================
156 */
157
158 //==========================================================================
159
160 boolean MML_CheckForEMS(void);
161 unsigned MML_SetupEMS(mminfo_t *mm);
162 void MML_ShutdownEMS(mminfo_t *mm);
163 unsigned MM_MapEMS(mminfo_t *mm);
164 boolean MML_CheckForXMS(mminfo_t *mm);
165 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
166 void MML_ShutdownXMS(mminfo_t *mm);
167 void MML_UseSpace(/*d*/word segstart, dword seglength, mminfo_t *mm);
168 void MML_ClearBlock(mminfo_t *mm);
169
170 void MM_Startup(mminfo_t *mm, mminfotype *mmi);
171 void MM_Shutdown(mminfo_t *mm);
172
173 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
174 void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
175 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
176 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
177 void MM_SortMem(mminfo_t *mm);
178 void MM_ShowMemory(mminfo_t *mm);
179 dword MM_UnusedMemory(mminfo_t *mm);
180 dword MM_TotalFree(mminfo_t *mm);
181 void MM_Report(mminfo_t *mm, mminfotype *mmi);
182 //int MM_EMSVer(void);
183 void MM_BombOnError(boolean bomb, mminfo_t *mm);
184 void MM_GetNewBlock(mminfo_t *mm);
185 void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
186
187 //==========================================================================
188
189 #endif