home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / imlib / port / dos4gw / doscall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-21  |  1.3 KB  |  68 lines

  1. #include "doscall.hpp"
  2. #include <stdlib.h>
  3. #include <i86.h>
  4. #include <string.hpp>
  5.  
  6.  
  7. void RM_intr(int intr, struct rminfo *rm)      // do a real-mode interrupt
  8. {
  9.   union REGS regs;
  10.   struct SREGS sregs;
  11.   memset(&sregs,0,sizeof(sregs));
  12.   regs.w.ax=0x0300;
  13.   regs.w.bx=intr;
  14.   regs.w.cx=0;
  15.   sregs.es=FP_SEG(rm);
  16.   regs.x.edi=FP_OFF(rm);
  17.   int386x(0x31,®s,®s,&sregs);  
  18. } ;
  19.  
  20. void *alloc_low_memory(long size)            // size in bytes
  21. {
  22.   rminfo rm;
  23.   memset(&rm,0,sizeof(rm));
  24.   rm.eax=0x4800;
  25.   rm.ebx=(size+15)/16;
  26.   RM_intr(0x21,&rm);
  27.   if (rm.flags&1)
  28.     return NULL;
  29.   else return (void *)((rm.eax&0xffff)<<4);
  30. }
  31.  
  32. void free_low_memory(void *ptr)
  33. {
  34.   rminfo rm;
  35.   memset(&rm,0,sizeof(rm));
  36.   rm.eax=0x4900;
  37.   rm.es=((unsigned long)ptr)>>4;
  38.   RM_intr(0x21,&rm);
  39.   if (rm.flags&1)
  40.   {
  41.     printf("Error while freeing low memory block\n");
  42.     exit(0);
  43.   }
  44. }
  45.  
  46. long low_memory_available()
  47. {
  48.   rminfo rm;
  49.   memset(&rm,0,sizeof(rm));
  50.   rm.eax=0x4800;
  51.   rm.ebx=0xffff;        // try to allocate the maximum size, dos while tells us how much is possible
  52.   RM_intr(0x21,&rm);
  53.   if (rm.flags&1)  
  54.     return rm.ebx*16;
  55.   else                  // this shouldn't succed, but just in case...
  56.   {
  57.     free_low_memory((void *)((rm.eax&0xffff)<<4));
  58.     return 0xffff*16;
  59.   }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.