1 /* Catacomb Apocalypse Source Code
2 * Copyright (C) 1993-2014 Flat Rock Software
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.
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.
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.
26 #include "src/lib/16_head.h"
27 #include "src/lib/16_hc.h"
28 //#include "src/lib/modex16.h"
29 //++++mh #include "src/lib/16_in.h"
31 #ifdef __DEBUG__ // 1 == Debug/Dev ; 0 == Production/final
32 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"
34 #define OUT_OF_MEM_MSG "\npee\n"
37 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
38 #define GETNEWBLOCK {if(!mm->mmfree)MML_ClearBlock(mm);mm->mmnew=mm->mmfree;mm->mmfree=mm->mmfree->next;}
40 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=mm->mmfree;mm->mmfree=x;}
42 #define AARED "\x1b[41;31m"
43 #define AABLUE "\x1b[44;34m"
44 #define AAGREEN "\x1b[42;32m"
45 #define AAYELLOW "\x1b[43;33m"
46 #define AAGREY "\x1b[47;37m"
47 #define AABLACK "\x1b[40;30m"
48 #define AAWHITE "\x1b[47;37m"
49 #define AAMAGENTA "\x1b[45;35m"
50 #define AARESET "\x1b[0m"
52 #define SAVENEARHEAP 0x200 // space to leave in data segment
53 #define SAVEFARHEAP 0//x400 // space to leave in far heap
55 #define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
57 #define MAXBLOCKS 1024
65 #define EMS_STATUS 0x40
66 #define EMS_GETFRAME 0x41
67 #define EMS_GETPAGES 0x42
68 #define EMS_ALLOCPAGES 0x43
69 #define EMS_MAPPAGE 0x44
70 #define EMS_MAPXPAGE 0x50
71 #define EMS_FREEPAGES 0x45
72 #define EMS_VERSION 0x46
76 #define XMS_VERSION 0x00
78 #define XMS_ALLOCHMA 0x01
79 #define XMS_FREEHMA 0x02
81 #define XMS_GENABLEA20 0x03
82 #define XMS_GDISABLEA20 0x04
83 #define XMS_LENABLEA20 0x05
84 #define XMS_LDISABLEA20 0x06
85 #define XMS_QUERYA20 0x07
87 #define XMS_QUERYREE 0x08
88 #define XMS_ALLOC 0x09
92 #define XMS_UNLOCK 0x0D
93 #define XMS_GETINFO 0x0E
94 #define XMS_RESIZE 0x0F
96 #define XMS_ALLOCUMB 0x10
97 #define XMS_FREEUMB 0x11
99 //==========================================================================
103 dword nearheap,farheap,EMSmem,XMSmem,mainmem;
106 //==========================================================================
108 extern void (* beforesort) (void);
109 extern void (* aftersort) (void);
110 extern void (* XMSaddr) (void); // far pointer to XMS driver
112 //==========================================================================
115 =============================================================================
119 =============================================================================
122 #define LOCKBIT 0x80 // if set in attributes, block cannot be moved
123 #define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
124 #define PURGEMASK 0xfffc
125 #define BASEATTRIBUTES 0 // unlocked, non purgable
128 #define MAPPAGES 4//mm->EMSpagesmapped
130 typedef struct mmblockstruct
133 //word start; dword length;
134 word blob; //for data larger than 64k
136 memptr *useptr; // pointer to the segment start
137 //huge struct mmblockstruct huge *next;
138 struct mmblockstruct far *next;
145 boolean mmstarted, bombonerror, mmerror;
146 //huge void huge *farheap;
152 void __near *nearheap;
155 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
157 word numUMBs,UMBbase[MAXUMBS];
158 //dword numUMBs,UMBbase[MAXUMBS];
159 //huge mmblocktype huge mmblocks[MAXBLOCKS],huge *mmhead,huge *mmfree,huge *mmrover,huge *mmnew;
160 mmblocktype far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;
164 =============================================================================
168 =============================================================================
173 =============================================================================
177 =============================================================================
180 //==========================================================================
182 boolean MML_CheckForEMS(void);
183 byte MML_SetupEMS(mminfo_t *mm);
184 void MML_ShutdownEMS(mminfo_t *mm);
185 byte MM_MapEMS(mminfo_t *mm, mminfotype *mmi);
186 byte MM_MapXEMS(mminfo_t *mm, mminfotype *mmi);
187 boolean MML_CheckForXMS(mminfo_t *mm);
188 void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
189 void MML_ShutdownXMS(mminfo_t *mm);
190 void MML_UseSpace(word segstart, dword seglength, mminfo_t *mm);
191 void MML_ClearBlock(mminfo_t *mm);
193 void MM_Startup(mminfo_t *mm, mminfotype *mmi);
194 void MM_Shutdown(mminfo_t *mm);
196 void MM_GetPtr(memptr *baseptr,dword size, mminfo_t *mm, mminfotype *mmi);
197 void MM_FreePtr(memptr *baseptr, mminfo_t *mm);
198 void MM_SetPurge(memptr *baseptr, int purge, mminfo_t *mm);
199 void MM_SetLock(memptr *baseptr, boolean locked, mminfo_t *mm);
200 void MM_SortMem(mminfo_t *mm);
201 void MM_ShowMemory(global_game_variables_t *gvar,/*page_t *page, */mminfo_t *mm);
202 void MM_DumpData(mminfo_t *mm);
203 dword MM_UnusedMemory(mminfo_t *mm);
204 dword MM_TotalFree(mminfo_t *mm);
205 void MM_Report(/*page_t *page, */mminfo_t *mm, mminfotype *mmi);
206 static void MM_EMSerr(byte *stri, byte err);
207 void MM_BombOnError(boolean bomb, mminfo_t *mm);
208 //void MM_GetNewBlock(mminfo_t *mm);
209 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
211 //==========================================================================