home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
files
/
program
/
lynxlib
/
tricks.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-23
|
2KB
|
72 lines
/* This source file is part of the LynxLib miscellaneous library by
Robert Fischer, and is Copyright 1990 by Robert Fischer. It costs no
money, and you may not make money off of it, but you may redistribute
it. It comes with ABSOLUTELY NO WARRANTY. See the file LYNXLIB.DOC
for more details.
To contact the author:
Robert Fischer \\80 Killdeer Rd \\Hamden, CT 06517 USA
(203) 288-9599 fischer-robert@cs.yale.edu */
/* Tricks in dealing with the OS */
#include <e_osbind.h>
/* ------------------------------------------------- */
char *malloc_highend(size)
/* Malloc's at the high end of memory */
LONG size;
{
char *mem; /* Temporary memory block */
LONG memsize; /* Full size of available memory */
char *out; /* Output thing */
/* Allocate at the high end of memory */
memsize = (LONG)Malloc(-1);
if (memsize <= size) return NULL;
mem = Malloc(memsize - size);
if (mem == NULL) return NULL;
out = Malloc(size);
Mfree(mem);
return out;
}
/* ------------------------------------------------- */
/* Allocates a "permanent" memory block in high memory */
char *PMalloc(size)
LONG size;
{
BASEPAGE *b, *old_b; /* For scanning the basepage linked list */
long usp;
char *block;
usp = Super(0L);
/* Find oldest basepage */
for (b = BP; b != NULL; b = (BASEPAGE *)(b->p_parent))
old_b = b;
/* Make that process temporarily the current process */
#ifdef DEBUG
if (CURPROC != BP) {
printf("Mismatch: CURPROC=%lx, BP=%lx\n", CURPROC, (long) BP);
Super(usp);
exit(1);
}
#endif
CURPROC = old_b;
/* Allocate memory */
block = malloc_highend(size);
/* Restore current process */
CURPROC = BP;
Super(usp);
return block;
}
/* ------------------------------------------------- */
term_res(out)
/* Terminates and stays resident, saving the text, data, bss and basepage */
int out; /* Output code */
{
Ptermres(BP->p_tlen + BP->p_dlen + BP->p_blen + 256, out);
}
/* ------------------------------------------------- */