1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2019 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
29 #include "src/lib/16_head.h"
\r
30 #include "src/lib/16_hc.h"
\r
31 #include "src/lib/16_tail.h"
\r
33 #ifdef __DEBUG__ // 1 == Debug/Dev ; 0 == Production/final
\r
34 #define OUT_OF_MEM_MSG "MM_GetPtr: Out of memory!\nYou were short :%lu bytes\n"
\r
36 #define OUT_OF_MEM_MSG "\n"
\r
39 //#define GETNEWBLOCK {if(!(mmnew=mmfree))Quit("MM_GETNEWBLOCK: No free blocks!") ;mmfree=mmfree->next;}
\r
40 #define GETNEWBLOCK {if(!gvar->mm.mmfree)MML_ClearBlock(gvar);gvar->mm.mmnew=gvar->mm.mmfree;gvar->mm.mmfree=gvar->mm.mmfree->next;}
\r
42 #define FREEBLOCK(x) {*x->useptr=NULL;x->next=gvar->mm.mmfree;gvar->mm.mmfree=x;}
\r
44 #define SAVENEARHEAP 0x400 // space to leave in data segment
\r
45 #define SAVEFARHEAP 0 // space to leave in far heap
\r
47 #define BUFFERSIZE 0x1000 // miscelanious, allways available buffer
\r
49 //moved to 16_tdef.h
\r
50 //#define MAXBLOCKS 1024
\r
55 #define EMS_INT 0x67
\r
56 #define EMM_INT 0x21
\r
58 #define EMS_STATUS 0x40
\r
59 #define EMS_GETFRAME 0x41
\r
60 #define EMS_GETPAGES 0x42
\r
61 #define EMS_ALLOCPAGES 0x43
\r
62 #define EMS_MAPPAGE 0x44
\r
63 #define EMS_MAPXPAGE 0x50
\r
64 #define EMS_FREEPAGES 0x45
\r
65 #define EMS_VERSION 0x46
\r
69 #define XMS_INT 0x2f
\r
70 #define XMS_CALL(v) _AH = (v);\
\r
71 __asm call [DWORD PTR XMSDriver]
\r
72 /*__asm { mov ah,[v]\*///}
\r
74 #define XMS_VERSION 0x00
\r
76 #define XMS_ALLOCHMA 0x01
\r
77 #define XMS_FREEHMA 0x02
\r
79 #define XMS_GENABLEA20 0x03
\r
80 #define XMS_GDISABLEA20 0x04
\r
81 #define XMS_LENABLEA20 0x05
\r
82 #define XMS_LDISABLEA20 0x06
\r
83 #define XMS_QUERYA20 0x07
\r
85 #define XMS_QUERYFREE 0x08
\r
86 #define XMS_ALLOC 0x09
\r
87 #define XMS_FREE 0x0A
\r
88 #define XMS_MOVE 0x0B
\r
89 #define XMS_LOCK 0x0C
\r
90 #define XMS_UNLOCK 0x0D
\r
91 #define XMS_GETINFO 0x0E
\r
92 #define XMS_RESIZE 0x0F
\r
94 #define XMS_ALLOCUMB 0x10
\r
95 #define XMS_FREEUMB 0x11
\r
97 //==========================================================================
\r
99 //typedef void _seg * memptr; //moved to 16_t.h
\r
103 dword nearheap,farheap,EMSmem,XMSmem,mainmem;
\r
104 } mminfotype;*/ //moved to 16_tdef.h
\r
106 //==========================================================================
\r
108 extern void (* beforesort) (void);
\r
109 extern void (* aftersort) (void);
\r
110 //extern void (* XMSaddr) (void); // far pointer to XMS driver
\r
111 extern dword XMSDriver;
\r
112 extern word XMSVer;
\r
114 //==========================================================================
\r
117 =============================================================================
\r
121 =============================================================================
\r
124 #define LOCKBIT 0x80 // if set in attributes, block cannot be moved
\r
125 #define PURGEBITS 3 // 0-3 level, 0= unpurgable, 3= purge first
\r
126 #define PURGEMASK 0xfffc
\r
127 #define BASEATTRIBUTES 0 // unlocked, non purgable
\r
129 //moved to typedefst
\r
130 //#define MAXUMBS 12
\r
131 #define MAPPAGES 4//gvar->mm.EMSpagesmapped
\r
133 //moved to typdefst
\r
134 /*typedef struct mmblockstruct
\r
137 //word start; dword length;
\r
138 word blob; //for data larger than 64k
\r
139 unsigned attributes;
\r
140 memptr *useptr; // pointer to the segment start
\r
141 struct mmblockstruct far *next;
\r
148 boolean mmstarted, bombonerror, mmerror;
\r
150 #ifdef __BORLANDC__
\r
154 void __near *nearheap;
\r
157 unsigned totalEMSpages,freeEMSpages,EMSpageframe,EMSpagesmapped,EMShandle;
\r
158 unsigned int EMSVer;
\r
159 word numUMBs,UMBbase[MAXUMBS];
\r
160 //dword numUMBs,UMBbase[MAXUMBS];
\r
161 mmblocktype far mmblocks[MAXBLOCKS],far *mmhead,far *mmfree,far *mmrover,far *mmnew;
\r
165 =============================================================================
\r
169 =============================================================================
\r
174 =============================================================================
\r
178 =============================================================================
\r
181 //==========================================================================
\r
183 boolean MML_CheckForEMS (void);
\r
184 //byte MML_SetupEMS(mminfo_t *mm);
\r
185 //void MML_ShutdownEMS(mminfo_t *mm);
\r
186 //byte MM_MapEMS(global_game_variables_t *gvar);
\r
187 //byte MM_MapXEMS(global_game_variables_t *gvar);
\r
188 boolean MML_CheckForXMS (void);
\r
189 //void MML_SetupXMS(mminfo_t *mm, mminfotype *mmi);
\r
190 //void MML_ShutdownXMS(mminfo_t *mm);
\r
191 void MML_UseSpace (unsigned segstart, unsigned seglength, global_game_variables_t *gvar);
\r
192 void MML_ClearBlock (global_game_variables_t *gvar);
\r
194 void MM_Reset (global_game_variables_t *gvar);
\r
195 void MM_Startup (global_game_variables_t *gvar);
\r
196 void MM_Shutdown (global_game_variables_t *gvar);
\r
198 void MM_GetPtr (memptr *baseptr,dword size, global_game_variables_t *gvar);
\r
199 void MM_FreePtr (memptr *baseptr, global_game_variables_t *gvar);
\r
200 void MM_SetPurge (memptr *baseptr, int purge, global_game_variables_t *gvar);
\r
201 void MM_SetLock (memptr *baseptr, boolean locked, global_game_variables_t *gvar);
\r
202 void MM_SortMem (global_game_variables_t *gvar);
\r
203 void MM_ShowMemory (global_game_variables_t *gvar);
\r
204 //void MM_ShowMemoryDetail (unsigned x, unsigned y, unsigned w, unsigned q, sdword end, mmshowmemoryinfo_t *scaninfo, global_game_variables_t *gvar);
\r
205 void MM_DumpData (global_game_variables_t *gvar);
\r
206 dword MM_UnusedMemory (global_game_variables_t *gvar);
\r
207 dword MM_TotalFree (global_game_variables_t *gvar);
\r
208 void MM_Report_ (global_game_variables_t *gvar);
\r
209 /*static */void MM_EMSerr (byte *stri, byte err);
\r
210 void MM_BombOnError (boolean bomb, global_game_variables_t *gvar);
\r
211 //void MM_GetNewBlock(mminfo_t *mm);
\r
212 //void MM_FreeBlock(mmblocktype *x, mminfo_t *mm);
\r
213 void xms_call (byte v, global_game_variables_t *gvar);
\r
215 //==========================================================================
\r