home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / getmem.pas < prev    next >
Pascal/Delphi Source File  |  1994-03-05  |  2KB  |  75 lines

  1. program GetMem;
  2. { Looks to page 0 (the PSP, field 2) of current running program, grabbing
  3.   "size of memory" integer (16-byte paragraph count).
  4.  
  5.   As explained on pages 262-263, Norton's Programmer's Guide for the IBM PC,
  6.   this is the same figure CHKDSK reports.  However amount of memory reported
  7.   may NOT be the actual physical size of memory.  It will show how much
  8.   memory can be used.
  9.  
  10.   Field 4 gives further information about memory if we have to work with
  11.   less than 64Kb available.  I haven't bothered with that at this point.
  12.   David Kirschbaum, Toad Hall
  13. }
  14.  
  15. TYPE
  16.   regpack = Record
  17.               ax,bx,cx,dx,bp,di,si,ds,es,flags: INTEGER;
  18.             END;
  19.  
  20. CONST
  21.   regs : regpack = (ax:0;bx:0;cx:0;dx:0;bp:0;di:0;si:0;ds:0;
  22.                     es:0;flags:0);
  23.  
  24. VAR
  25.   rec     : regpack Absolute regs;
  26.   k,
  27.   ourDSeg,
  28.   ourCSeg : INTEGER;
  29.   r,
  30.   maxmem,
  31.   k64     : REAL;
  32.  
  33. PROCEDURE GetSize;
  34.   {uses DOS interrupt 18 AND low-memory location 413H}
  35.   BEGIN
  36.     Intr($12,rec);             { get usable memory in Kb}
  37.     k := rec.ax;               { here's the Kb}
  38.     maxmem := k * 1024.0;      { bytify it}
  39.     Write('Interrupt 18 system Kb: ',k:3);
  40.     k := Memw[0000:$0413];    { also kept in low memory}
  41.     Write(', and low memory value: ',k:3);
  42.     Writeln(' (',maxmem:6:0,' bytes)');
  43.     Writeln('They oughtta be the same!');
  44.   END;
  45.  
  46. PROCEDURE GetMem;
  47.  
  48.     FUNCTION CMem(Seg : INTEGER) : REAL;
  49.       BEGIN
  50.         k := MemW[Seg:$0002];
  51.         if k >= 0 THEN r := k * 1.0    {compensate for stupid maxint}
  52.         ELSE r := k64 + (k * 1.0);
  53.         write(': paragraphs used: ',r:5:0);
  54.         r := r * 16.0;
  55.         Write(' (bytes: ',r:7:0);
  56.         CMem := maxmem - r;
  57.         Write('), remaining: ');
  58.       END;
  59.  
  60.   BEGIN
  61.     {show you what likely segment registers return}
  62.     Writeln('ourCSeg: ',ourCSeg:6, CMem(ourCSeg):7:0);
  63.     Writeln('ourDSeg: ',ourDSeg:6, CMem(ourDSeg):7:0);
  64.     Writeln('   CSEG: ',   CSeg:6, CMem(CSEG):7:0);
  65.     Writeln('   DSEG: ',   DSeg:6, CMem(DSEG):7:0);
  66.   END;
  67.  
  68. BEGIN
  69.   k64 := 1024.0 * 64.0;
  70.   GetSize;
  71.   ourDSeg := rec.ds;
  72.   ourCSeg := rec.es;
  73.   GetMem;
  74. END.
  75.