home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name isremove -- Remove resident program
- *
- * Synopsis ercode = isremove(psp_seg);
- *
- * int ercode Error code from DOS function 0x49:
- * 0 if okay, nonzero if error.
- * unsigned psp_seg Segment of Program Segment Prefix
- * of resident program.
- *
- * Description This function removes from memory a program that has
- * previously terminated and stayed resident via ISRESEXT.
- *
- * WARNING: Any interrupt vectors or chained interrupt
- * service that invoke any portion of the resident program
- * MUST be re-vectored or otherwise disabled BEFORE the
- * program is removed. Serious problems may result
- * otherwise.
- *
- * Method This function works by following the chain of DOS memory
- * control blocks via MMCTRL. The control blocks are
- * located at increasing memory addresses, so we begin
- * searching at the first memory control block, as reported
- * by MMFIRST. For each control block that belongs to
- * psp_seg, we free the associated memory block via DOS
- * function 0x49. All memory blocks belonging to the
- * specified program are freed, regardless of their
- * location.
- *
- * Results ercode Error code from DOS function 0x49.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1986,1987,1989
- *
- **/
-
- #include <dos.h> /* For intdosx(), REGS, and */
- /* SREGS. */
-
- #include <bintrupt.h>
-
- static int mm_free(unsigned); /* Internal function (see */
- /* below). */
-
- int isremove(psp_seg)
- unsigned psp_seg;
- {
- unsigned memblock,nextblock;
- int result;
- MEMCTRL ctlblock;
-
- result = 9; /* In case first block address */
- /* is bad, return 9 (Invalid */
- /* memory block). */
-
- /* Begin memory block search at first memory block. */
-
- for (memblock = mmfirst();
- memblock != 0;
- memblock = nextblock)
- {
- if ( 9 != mmctrl(memblock,&ctlblock,&nextblock)
- /* If block okay */
- && ctlblock.owner_psp == psp_seg) /* and belongs to */
- { /* psp_seg, */
- result = mm_free(memblock); /* then free the block. */
- if (result != 0)
- break; /* Quit if error. */
- }
- }
-
- return result;
- }
-
- /**
- *
- * Name mm_free -- Release an allocated memory block
- *
- * Synopsis ercode = mm_free(seg);
- *
- * int ercode Returned error code (0 if okay).
- * unsigned seg Segment address of memory block.
- *
- * Description This function frees memory blocks that have been
- * allocated by DOS function 0x48. The segment address
- * given must be associated with a previously allocated
- * block.
- *
- * Returns ercode DOS function return code.
- *
- **/
-
- static int mm_free(seg)
- unsigned seg;
- {
- union REGS regs;
- struct SREGS sregs;
-
- regs.h.ah = 0x49;
- sregs.es = seg;
- intdosx(®s,®s,&sregs);
-
- return ((regs.x.cflag) ? (regs.h.al) /* Nonzero error code. */
- : (0)); /* Success: return 0. */
- }