home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBOPAS / MEMSZ104.LBR / MEMSZ104.PQS / MEMSZ104.PAS
Pascal/Delphi Source File  |  2000-06-30  |  5KB  |  171 lines

  1.  
  2.  
  3.  
  4.  
  5. program MemSiz;
  6.  
  7.  
  8.   {MEMSIZ.PAS #1.04 85-07-16
  9.               DEMONSTRATE ADJUSTMENT TO SIZE OF CP/M-80 SYSTEM
  10.  
  11.       V01 L04  updated 85-07-16 by DEH to use tidier parameter settings.
  12.           L01  created on 85-07-10 by Dennis E. Hamilton to report on CP/M-
  13.                80 TPA memory usage on the system being used.}
  14.  
  15.  
  16.  
  17. const
  18.  
  19.   ProgramTop = $3000; {<<<< MUST AGREE WITH COMPILER E-OPTION VALUE <<<<}
  20.                    {Recompile the program repeatedly,  varying the E-Option
  21.                     (for  compiling to .COM) to the least hexadecimal value
  22.                     that compiles successfully.   Then insert that value as
  23.                     ProgramTop and recompile with that setting. }
  24.  
  25.    StackSize = $0400;
  26.  
  27.  
  28.  
  29. var       CO: text;
  30.               {File used to receive the program's report}
  31.  
  32.  
  33. procedure
  34.  
  35.    HexWord(v: integer);
  36.  
  37.    procedure HexByte(b: byte);
  38.  
  39.       procedure HexNibble(n: byte);
  40.          const hexes:string[16] = '0123456789ABCDEF';
  41.          begin {display hex code for low-order 4 bits of n}
  42.          write(CO, hexes[succ(n and $0f)] );
  43.          end {HexNibble};
  44.  
  45.       begin {display the two hex codes for the byte value b}
  46.       HexNibble(b shr 4); HexNibble(b);
  47.       end {HexByte};
  48.  
  49.    begin {HexWord display of 16-bit value in Hexadecimal code}
  50.    write(CO, '$'); HexByte(Hi(v)); HexByte(Lo(v));
  51.    end {HexWord};
  52.  
  53.  
  54. procedure uint(i: integer);
  55.  
  56.    begin {show unsigned value in 6-byte field}
  57.    if i < 0
  58.    then Write(CO, 65535.0+succ(i) :6:0)
  59.    else Write(CO, i :6);
  60.    end {uint};
  61.  
  62.  
  63.                                                                    { . . . }
  64. {MEMSIZ.PAS 1.04: 85-07-16                                            page 2}
  65.  
  66.  
  67. procedure ubytes(u: integer);
  68.  
  69.    begin {show byte count in both decimal and hex}
  70.    uint(u); write(CO, '-byte ('); HexWord(u); write(CO, ') ');
  71.    end {ubytes};
  72.  
  73.  
  74. procedure indent;
  75.  
  76.    begin write(CO, '        '); end {indent 8 spaces};
  77.  
  78.  
  79.  
  80. var     HP: ^byte;
  81.             {Derived HeapPtr starter value}
  82.  
  83.      BDOSE: integer absolute $0006;
  84.               {holding  the address for the CP/M system's  currently-lowest
  85.                point in memory}
  86.  
  87.  
  88. BEGIN {MEMSIZ}
  89.  
  90. {Switch to CP/M-80 dynamic Free Zone: }
  91.   if ParamCount = 0
  92.   then begin
  93.        StackPtr := BDOSE;
  94.        RecurPtr := StackPtr - StackSize;
  95.        HP := ptr(ProgramTop); {V01 L03}
  96.        Release(HP);
  97.        end {conditional initialization};
  98.  
  99.  
  100. assign(CO, 'CON:'); {#1.01; #1.00 used 'MEMSIZ.DAT'}
  101.   rewrite(CO); {Direct output to suitable file or device.}
  102.  
  103.  
  104. {Tell the folks who we are: }
  105.   writeln(CO, 'MEMSIZ> #1.04 85-07-16 CPM-80 DYNAMIC MEMORY REPORT');
  106.   writeln(CO);
  107.  
  108.  
  109. {Show key memory-management pointer values: }
  110.   indent; HexWord(BDOSE); writeln(CO, ' current CP/M base');
  111.   indent; HexWord(StackPtr-1); writeln(CO, ' Stack ceiling');
  112.   indent; HexWord(RecurPtr-1); writeln(CO, ' Heap ceiling');
  113.   indent; HexWord(HeapPtr); writeln(CO, ' Heap base');
  114.  
  115.  
  116. {Describe the Free Zone & MemAvail for dynamic use right now: }
  117.   indent; indent; ubytes(StackPtr-HeapPtr); writeln(CO, 'Free Zone');
  118.   indent; indent; ubytes(MemAvail); writeln(CO, 'MemAvail');
  119.  
  120.  
  121. {Describe the area used for program and data: }
  122.   indent; HexWord(ProgramTop-1); writeln(CO, ' program end address');
  123.   indent; HexWord(addr(HP));  writeln(CO, ' program data area');
  124.   indent; HexWord($0100); writeln(CO, ' program base address');
  125.  
  126.                                                                    { . . . }
  127. {MEMSIZ.PAS 1.04: 85-07-16                                            page 3}
  128.  
  129.  
  130. {Comment on amount used versus amount available: }
  131.   indent; indent; ubytes(BDOSE - $0100);
  132.     writeln(CO, 'TPA capacity');
  133.   indent; indent;
  134.     if ParamCount = 0
  135.     then ubytes(StackPtr - $0100)
  136.     else ubytes(ProgramTop - $0100); {V01 L03}
  137.     writeln(CO, 'TPA taken');
  138.  
  139.  
  140. writeln(CO);
  141.  
  142.  
  143. {Explain which variation is being seen: }
  144.  
  145.   if ParamCount = 0
  146.  
  147.   then begin
  148.        writeln(CO, ' This memory mapping is obtained after establishing');
  149.        writeln(CO, ' a dynamic Free Zone.  Program data is kept safe at');
  150.        writeln(CO, ' low addresses, with the Free Zone allowed to claim');
  151.        writeln(CO, ' all higher memory left over below CP/M.  To see a');
  152.        writeln(CO, ' typical static allocation, use a command-line such');
  153.        writeln(CO, ' as');
  154.        writeln(CO, '               B0>MEMSIZ STATIC');
  155.        end
  156.  
  157.   else begin
  158.        writeln(CO, ' This is a standard compiler-determined allocation,');
  159.        writeln(CO, ' using the default or option-selected program end-');
  160.        writeln(CO, ' address as the highest-used location.  The program');
  161.        writeln(CO, ' data area sits above the stack and heap area.  If');
  162.        writeln(CO, ' a low end address is not specified by the user, it');
  163.        writeln(CO, ' is possible to overlay the CP/M system with values');
  164.        writeln(CO, ' of program variables.');
  165.        end;
  166.  
  167.  
  168. close(CO);
  169.  
  170. END. {MEMSIZ.PAS}
  171.