1 /* Catacomb Apocalypse Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\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
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
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
25 #include "src/lib/16_head.h"
\r
26 #include "src/lib/16_hc.h"
\r
27 #include "src/lib/16_tail.h"
\r
28 //++++mh #include "src/lib/16_in.h"
\r
30 #ifdef __DEBUG__ // 1 == Debug/Dev ; 0 == Production/final
\r
31 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"
\r
33 #define OUT_OF_MEM_MSG "\npee\n"
\r
36 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
\r
37 #define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}
\r
39 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}
\r
41 #define SAVENEARHEAP 0x200 // space to leave in data segment
\r
42 #define SAVEFARHEAP 0//x400 // space to leave in far heap
\r
44 #define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
\r
47 //#define MAXBLOCKS 1024
\r
53 #define EMS_INT 0x67
\r
54 #define EMM_INT 0x21
\r
56 #define EMS_STATUS 0x40
\r
57 #define EMS_GETFRAME 0x41
\r
58 #define EMS_GETPAGES 0x42
\r
59 #define EMS_ALLOCPAGES 0x43
\r
60 #define EMS_MAPPAGE 0x44
\r
61 #define EMS_MAPXPAGE 0x50
\r
62 #define EMS_FREEPAGES 0x45
\r
63 #define EMS_VERSION 0x46
\r
67 #define XMS_INT 0x2f
\r
68 #define XMS_CALL(v) _AH = (v);\
\r
69 __asm call [DWORD PTR XMSDriver]
\r
70 /*__asm { mov ah,[v]\*///}
\r
72 #define XMS_VERSION 0x00
\r
74 #define XMS_ALLOCHMA 0x01
\r
75 #define XMS_FREEHMA 0x02
\r
77 #define XMS_GENABLEA20 0x03
\r
78 #define XMS_GDISABLEA20 0x04
\r
79 #define XMS_LENABLEA20 0x05
\r
80 #define XMS_LDISABLEA20 0x06
\r
81 #define XMS_QUERYA20 0x07
\r
83 #define XMS_QUERYFREE 0x08
\r
84 #define XMS_ALLOC 0x09
\r
85 #define XMS_FREE 0x0A
\r
86 #define XMS_MOVE 0x0B
\r
87 #define XMS_LOCK 0x0C
\r
88 #define XMS_UNLOCK 0x0D
\r
89 #define XMS_GETINFO 0x0E
\r
90 #define XMS_RESIZE 0x0F
\r
92 #define XMS_ALLOCUMB 0x10
\r
93 #define XMS_FREEUMB 0x11
\r
95 //==========================================================================
\r
100 dword nearheap,farheap,EMSmem,XMSmem,mainmem;
\r
103 //==========================================================================
\r
105 extern void (* beforesort) (void);
\r
106 extern void (* aftersort) (void);
\r
107 extern void (* XMSaddr) (void); // far pointer to XMS driver
\r
108 extern dword XMSDriver;
\r
109 extern word XMSVer;
\r
111 //==========================================================================
\r
114 =============================================================================
\r
118 =============================================================================
\r
121 #define LOCKBIT 0x80 // if set in attributes, block cannot be moved
\r
122 #define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
\r
123 #define PURGEMASK 0xfffc
\r
124 #define BASEATTRIBUTES 0 // unlocked, non purgable
\r
126 //moved to typedefst
\r
127 //#define MAXUMBS 12
\r
128 #define MAPPAGES 4//gvar->mm.EMSpagesmapped
\r
130 //moved to typdefst
\r
131 /*typedef struct mmblockstruct
\r
134 //word start; dword length;
\r
135 word blob; //for data larger than 64k
\r
136 unsigned attributes;
\r
137 memptr *useptr; // pointer to the segment start
\r
138 struct mmblockstruct far *next;
\r
145 boolean mmstarted, bombonerror, mmerror;
\r
147 #ifdef __BORLANDC__
\r
151 void __near *nearheap;
\r
154 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
\r
155 unsigned int EMSVer;
\r
156 word numUMBs,UMBbase[MAXUMBS];
\r
157 //dword numUMBs,UMBbase[MAXUMBS];
\r
158 mmblocktype far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;
\r
162 =============================================================================
\r
166 =============================================================================
\r
171 =============================================================================
\r
175 =============================================================================
\r
178 //==========================================================================
\r
180 boolean MML_CheckForEMS(void);
\r
181 //byte MML_SetupEMS(mminfo_t *mm);
\r
182 //void MML_ShutdownEMS(mminfo_t *mm);
\r
183 byte MM_MapEMS(global_game_variables_t *gvar);
\r
184 //byte MM_MapXEMS(global_game_variables_t *gvar);
\r
185 boolean MML_CheckForXMS(void);
\r
186 //void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
\r
187 //void MML_ShutdownXMS(mminfo_t *mm);
\r
188 void MML_UseSpace(word segstart, dword seglength, global_game_variables_t *gvar);
\r
189 void MML_ClearBlock(global_game_variables_t *gvar);
\r
191 void MM_Startup(global_game_variables_t *gvar);
\r
192 void MM_Shutdown(global_game_variables_t *gvar);
\r
194 void MM_GetPtr(memptr *baseptr,dword size, global_game_variables_t *gvar);
\r
195 void MM_FreePtr(memptr *baseptr, global_game_variables_t *gvar);
\r
196 void MM_SetPurge(memptr *baseptr, int purge, global_game_variables_t *gvar);
\r
197 void MM_SetLock(memptr *baseptr, boolean locked, global_game_variables_t *gvar);
\r
198 void MM_SortMem(global_game_variables_t *gvar);
\r
199 void MM_ShowMemory(global_game_variables_t *gvar);
\r
200 void MM_DumpData(global_game_variables_t *gvar);
\r
201 dword MM_UnusedMemory(global_game_variables_t *gvar);
\r
202 dword MM_TotalFree(global_game_variables_t *gvar);
\r
203 void MM_Report_(global_game_variables_t *gvar);
\r
204 /*static */void MM_EMSerr(byte *stri, byte err);
\r
205 void MM_BombOnError(boolean bomb, global_game_variables_t *gvar);
\r
206 //void MM_GetNewBlock(mminfo_t *mm);
\r
207 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
\r
208 void xms_call(byte v, global_game_variables_t *gvar);
\r
210 //==========================================================================
\r