1 /* Project 16 Source Code~
2 * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669
4 * This file is part of Project 16.
6 * Project 16 is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Project 16 is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
19 * Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "src/lib/16_head.h"
25 /* Function: Wait **********************************************************
\r
27 * Parameters: wait - time in microseconds
\r
29 * Description: pauses for a specified number of microseconds.
\r
32 void wait(clock_t wait){
\r
37 goal = wait + clock();
\r
38 while((goal > clock()) && !kbhit()) ;
\r
41 void* AllocateLargestFreeBlock(size_t* Size)
46 s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
48 while (s0 && (p = malloc(s0)) == NULL)
58 if ((p = malloc(s0 + s1)) != NULL)
66 while (s0 && (p = malloc(s0)) == NULL)
73 size_t GetFreeSize(void)
82 void* p = AllocateLargestFreeBlock(&largest);
84 if (largest < sizeof(void*))
104 while (pFirst != NULL)
106 void* p = *(void**)pFirst;
114 void far* AllocateLargestFarFreeBlock(size_t far* Size)
119 s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
120 while (s0 && (p = _fmalloc(s0)) == NULL)
129 if ((p = _fmalloc(s0 + s1)) != NULL)
136 while (s0 && (p = _fmalloc(s0)) == NULL)
143 size_t GetFarFreeSize(void)
146 void far* pFirst = NULL;
147 void far* pLast = NULL;
151 void far* p = AllocateLargestFarFreeBlock(&largest);
152 if (largest < sizeof(void far*))
158 *(void far* far*)p = NULL;
164 *(void far* far*)pLast = p;
168 while (pFirst != NULL)
170 void far* p = *(void far* far*)pFirst;
178 void __near* AllocateLargestNearFreeBlock(size_t* Size)
183 s0 = ~(size_t)0 ^ (~(size_t)0 >> 1);
184 while (s0 && (p = _nmalloc(s0)) == NULL)
193 if ((p = _nmalloc(s0 + s1)) != NULL)
200 while (s0 && (p = _nmalloc(s0)) == NULL)
207 size_t GetNearFreeSize(void)
210 void __near* pFirst = NULL;
211 void __near* pLast = NULL;
215 void __near* p = AllocateLargestNearFreeBlock(&largest);
216 if (largest < sizeof(void __near*))
222 *(void __near* __near*)p = NULL;
228 *(void __near* __near*)pLast = p;
232 while (pFirst != NULL)
234 void __near* p = *(void __near* __near*)pFirst;
244 long int save_pos, size_of_file;
\r
246 save_pos = ftell(fp);
\r
247 fseek(fp, 0L, SEEK_END);
\r
248 size_of_file = ftell(fp);
\r
249 fseek(fp, save_pos, SEEK_SET);
\r
250 return(size_of_file);
\r
253 ///////////////////////////////////////////////////////////////////////////
\r
255 // US_CheckParm() - checks to see if a string matches one of a set of
\r
256 // strings. The check is case insensitive. The routine returns the
\r
257 // index of the string that matched, or -1 if no matches were found
\r
259 ///////////////////////////////////////////////////////////////////////////
\r
261 US_CheckParm(char *parm,char **strings)
\r
267 while (!isalpha(*parm)) // Skip non-alphas
\r
270 for (i = 0;*strings && **strings;i++)
\r
272 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
\r
289 ==========================
\r
293 ==========================
\r
296 /*void Quit(char *error, ...)
\r
299 unsigned finscreen;
\r
303 va_start(ap,error);
\r
309 CA_CacheGrChunk (PIRACY);
\r
310 finscreen = (unsigned)grsegs[PIRACY];
\r
316 if (error && *error)
\r
325 movedata (finscreen,0,0xb800,0,4000);
\r
336 _argv[1] = "LAST.SHL";
\r
337 _argv[2] = "ENDSCN.SCN";
\r
339 if (execv("LOADSCN.EXE", _argv) == -1)
\r
342 puts("Couldn't find executable LOADSCN.EXE.\n");
\r