home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol094 / memavail.src < prev    next >
Encoding:
Text File  |  1984-04-29  |  1.3 KB  |  47 lines

  1. ;--------------------------------------------------------
  2. ;program title:        Memory Available
  3. ;author:        Peter Grogono
  4. ;date written:        May 1982
  5. ;source:        Pascal/Z Users' Group newsletter
  6. ;            May 1982 issue.
  7. ;
  8. ;DECLARE:
  9. ;    FUNCTION MEMAVAIL: INTEGER; EXTERNAL;
  10. ;
  11. ;EXAMPLE CALL:
  12. ;    if ( memavail >= 0 ) and ( memavail < 250 ) then
  13. ;        <execute short of space routine>
  14. ;    else
  15. ;        <enough space>;
  16. ;
  17. ;SUMMARY:
  18. ;Returns the difference in value between the top of the heap and the
  19. ;stack as an integer value.  If the value returned is greater than
  20. ;32767, Pascal will consider it to be negative. You can correct for
  21. ;this by subtracting the value from 65536.  For example: assume
  22. ;memavail = -12000 then there are 65536 + (-12000) = 53536 bytes of
  23. ;unused memory.
  24. ; short program example:
  25. ;        var    free: real;
  26. ;        function memavail: integer; external;
  27. ;        ...
  28. ;        if memavail < 0 then
  29. ;           free := 65537.0 + memavail
  30. ;        else
  31. ;           free := memavail;
  32. ;        writeln ( free:6:0 );
  33. ;--------------------------------------------------------
  34.     entry    memavail
  35.     name    memavail
  36. memavail:    
  37.     push    ix
  38.     pop    h    ;HL = address of top of stack
  39.     exx
  40.     push    h
  41.     exx
  42.     pop    d    ;now DE = address of top of heap
  43.     dsbc    d    ;HL = distance between heap & stack
  44.     xchg        ;put it in DE for Pascal/Z
  45.     ret        ;all done
  46. ;--------------------------------------------------------
  47.