home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name mmavail -- Report available memory in an IBM PC.
- *
- * Synopsis ercode = mmavail(pmain_mem,pext_mem,pextads);
- *
- * int ercode 0 if okay, 1 if error
- * int *pmain_mem Returned size of largest contiguous
- * block of available main memory (in
- * 1024-byte units)
- * int *pext_mem Returned amount of available extended
- * memory (in 1024-byte units)
- * long *pextads Returned 24-bit physical address of
- * the first free location in extended
- * memory
- *
- * Description MMAVAIL reports the capacity of two different areas of
- * memory: (1) the largest block that can be allocated by
- * MMALLOC; and (2) the portion of extended memory above
- * any installed VDISKs. If any memory of type (2) is
- * available, its initial address is also returned.
- *
- * If this is not an IBM PC-AT (or compatible) with
- * extended memory available above installed VDISKs, then
- * both *pext_mem and *pextads are zero.
- *
- * An error is reported if DOS's memory control blocks are
- * destroyed.
- *
- * Returns ercode 0 if okay, 1 if error
- * *pmain_mem Size of largest contiguous
- * block of available main memory (in
- * 1024-byte units)
- * *pext_mem Amount of available extended memory
- * (in 1024-byte units)
- * *pextads The 24-bit physical address of the
- * first free location in extended memory
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <string.h>
-
- #include <bisr.h>
- #include <bmemory.h>
- #include <bquery.h>
-
- int mmavail(pmain_mem,pext_mem,pextads)
- int *pmain_mem,*pext_mem;
- long *pextads;
- {
- int result;
- ADS xads_ads;
- ADS vdisk_ads;
- unsigned seg,main_paragraphs;
-
- char signature[6]; /* Local copy of possible VDISK */
- /* signature. */
- ADS sign_ads; /* Address of signature[]. */
- int dummy;
-
- if (mmalloc(0xffff,&seg,&main_paragraphs) == 8)
- {
- *pmain_mem = main_paragraphs >> 6;
- result = 0;
- }
- else
- {
- *pmain_mem = 0;
- result = 1;
- }
-
- if (*pext_mem = mmtotal(&dummy))
- { /* There is extended memory. */
-
- /* Check address pointed to by interrupt 0x19 for signature */
- /* of VDISK code. */
-
- isretvec(0x19,&vdisk_ads);
- vdisk_ads.r = 0x0012;
- utabsptr(signature,&sign_ads);
- utslmove(&vdisk_ads,&sign_ads,5);
- signature[5] = '\0';
-
- if (strcmp(signature,"VDISK") == 0)
- {
- /* Signature found: now extract the */
- /* three bytes denoting the first */
- /* available byte in extended memory. */
- /* Put result into *pextads. */
- vdisk_ads.r = 0x002c;
- utabsptr((char *) pextads,&xads_ads);
- *pextads = 0L;
- utslmove(&vdisk_ads,&xads_ads,3);
-
- /* Round first free address up to next */
- /* multiple of 1024 bytes; convert to */
- /* kilobytes; deduct 1024K to measure */
- /* portion above main memory. */
- /* This gives number of 1K blocks of */
- /* extended memory used by VDISK. */
- /* Subtract this from total extended */
- /* memory to get free portion of */
- /* extended memory. */
-
- *pext_mem -= (int) ((*pextads + 1023L) >> 10) - 1024;
- if (*pext_mem == 0)
- *pextads = 0L;
- }
- else /* VDISK signature not found so infer */
- { /* that all extended memory is free. */
- *pextads = 0x100000L;
- }
- }
- else
- { /* No extended memory present. */
- *pextads = 0L;
- }
-
- return result;
- }