home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name mmalloc -- Allocate memory outside of program
- * (Formerly called PCALLOC.)
- *
- * Synopsis ercode = mmalloc(request,pseg,psize);
- *
- * int ercode Returned error code
- * unsigned request Number of paragraphs requested
- * unsigned *pseg Segment address of allocated block
- * unsigned *psize Size in paragraphs of allocated block
- *
- * Description MMALLOC allocates a block of memory. The requested size
- * of the block is specified by "request" in units called
- * paragraphs (16 bytes). The next (higher in memory)
- * available block of memory is allocated and the starting
- * segment address is returned. If more memory is
- * requested than is available, the amount of available
- * memory is returned, but no block is actually allocated.
- *
- * Use MMFREE to release the allocated memory back to DOS.
- * Use MMSETBLK to request that the block of memory be
- * grown or shrunk.
- *
- * Returns ercode Returned DOS error code.
- * *pseg Segment address of memory block allocated.
- * *psize Size (in paragraphs) of memory block which
- * is allocated, or (if requested amount
- * of memory is too large) the available
- * memory size.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bmemory.h>
- #include <butility.h>
-
- int mmalloc(request,pseg,psize)
- unsigned request,*pseg,*psize;
- {
- DOSREG dos_reg;
- int ercode;
-
- dos_reg.ax = 0x4800;
- dos_reg.bx = request;
- ercode = dos(&dos_reg); /* Invoke DOS function 0x48h */
- *pseg = 0xffff; /* Initialize to bad address */
- if (ercode == 0)
- {
- *pseg = dos_reg.ax; /* Segment address */
- *psize = dos_reg.bx; /* Segment size */
- }
- else if (ercode == 8)
- *psize = dos_reg.bx; /* Insufficient memory */
- else
- *psize = 0;
-
- return(ercode);
- }