home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / MMAVAIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  3.6 KB  |  123 lines

  1. /**
  2. *
  3. * Name        mmavail -- Report available memory in an IBM PC.
  4. *
  5. * Synopsis    ercode = mmavail(pmain_mem,pext_mem,pextads);
  6. *
  7. *        int ercode      0 if okay, 1 if error
  8. *        int *pmain_mem      Returned size of largest contiguous
  9. *                  block of available main memory (in
  10. *                  1024-byte units)
  11. *        int *pext_mem      Returned amount of available extended
  12. *                  memory (in 1024-byte units)
  13. *        long *pextads      Returned 24-bit physical address of
  14. *                  the first free location in extended
  15. *                  memory
  16. *
  17. * Description    MMAVAIL reports the capacity of two different areas of
  18. *        memory:  (1) the largest block that can be allocated by
  19. *        MMALLOC; and (2) the portion of extended memory above
  20. *        any installed VDISKs.  If any memory of type (2) is
  21. *        available, its initial address is also returned.
  22. *
  23. *        If this is not an IBM PC-AT (or compatible) with
  24. *        extended memory available above installed VDISKs, then
  25. *        both *pext_mem and *pextads are zero.
  26. *
  27. *        An error is reported if DOS's memory control blocks are
  28. *        destroyed.
  29. *
  30. * Returns    ercode          0 if okay, 1 if error
  31. *        *pmain_mem      Size of largest contiguous
  32. *                  block of available main memory (in
  33. *                  1024-byte units)
  34. *        *pext_mem      Amount of available extended memory
  35. *                  (in 1024-byte units)
  36. *        *pextads      The 24-bit physical address of the
  37. *                  first free location in extended memory
  38. *
  39. * Version    3.0  (C)Copyright Blaise Computing Inc.  1986
  40. *
  41. **/
  42.  
  43. #include <string.h>
  44.  
  45. #include <bisr.h>
  46. #include <bmemory.h>
  47. #include <bquery.h>
  48.  
  49. int mmavail(pmain_mem,pext_mem,pextads)
  50. int *pmain_mem,*pext_mem;
  51. long *pextads;
  52. {
  53.     int      result;
  54.     ADS      xads_ads;
  55.     ADS      vdisk_ads;
  56.     unsigned seg,main_paragraphs;
  57.  
  58.     char signature[6];          /* Local copy of possible VDISK          */
  59.                   /*   signature.                  */
  60.     ADS  sign_ads;          /* Address of signature[].          */
  61.     int  dummy;
  62.  
  63.     if (mmalloc(0xffff,&seg,&main_paragraphs) == 8)
  64.     {
  65.     *pmain_mem = main_paragraphs >> 6;
  66.     result       = 0;
  67.     }
  68.     else
  69.     {
  70.     *pmain_mem = 0;
  71.     result       = 1;
  72.     }
  73.  
  74.     if (*pext_mem = mmtotal(&dummy))
  75.     {                      /* There is extended memory.    */
  76.  
  77.     /* Check address pointed to by interrupt 0x19 for signature       */
  78.     /* of VDISK code.                              */
  79.  
  80.     isretvec(0x19,&vdisk_ads);
  81.     vdisk_ads.r = 0x0012;
  82.     utabsptr(signature,&sign_ads);
  83.     utslmove(&vdisk_ads,&sign_ads,5);
  84.     signature[5] = '\0';
  85.  
  86.     if (strcmp(signature,"VDISK") == 0)
  87.     {
  88.                   /* Signature found:  now extract the    */
  89.                   /* three bytes denoting the first       */
  90.                   /* available byte in extended memory.   */
  91.                   /* Put result into *pextads.          */
  92.         vdisk_ads.r = 0x002c;
  93.         utabsptr((char *) pextads,&xads_ads);
  94.         *pextads    = 0L;
  95.         utslmove(&vdisk_ads,&xads_ads,3);
  96.  
  97.                   /* Round first free address up to next  */
  98.                   /* multiple of 1024 bytes; convert to   */
  99.                   /* kilobytes; deduct 1024K to measure   */
  100.                   /* portion above main memory.          */
  101.                   /* This gives number of 1K blocks of    */
  102.                   /* extended memory used by VDISK.       */
  103.                   /* Subtract this from total extended    */
  104.                   /* memory to get free portion of          */
  105.                   /* extended memory.              */
  106.  
  107.         *pext_mem -= (int) ((*pextads + 1023L) >> 10) - 1024;
  108.         if (*pext_mem == 0)
  109.         *pextads = 0L;
  110.     }
  111.     else              /* VDISK signature not found so infer   */
  112.     {              /* that all extended memory is free.    */
  113.         *pextads = 0x100000L;
  114.     }
  115.     }
  116.     else
  117.     {                      /* No extended memory present.  */
  118.     *pextads = 0L;
  119.     }
  120.  
  121.     return result;
  122. }
  123.