home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #3.1 / RBBSIABOX31.cdr / typd / turbmem.fix < prev    next >
Encoding:
Text File  |  1990-09-29  |  3.0 KB  |  71 lines

  1. (*  TURBMEM.FIX  by Jim Gronek, Phoenix, Az. 08/23/1985
  2.  
  3.     Module to allow Turbo Pascal programs to automatically adjust
  4.     its Stack Pointer, Recursion Pointer and Heap Pointer to use
  5.     all available memory in the TPA.  Note that this routine will
  6.     require that you compile your program twice, once without this
  7.     routine to get the default code and data block sizes, and once
  8.     with this module after adjusting the Heap Pointer address.
  9.  
  10.     To calculate the correct Heap Pointer address, compile the program
  11.     with the default address used by Turbo in the .COM file mode.
  12.     When the program has finished compiling, it will report statistics
  13.     on the memory utilization, as follows:
  14.  
  15.       Code : 19487 bytes (1FC9-6BE8)     {example settings only!}
  16.       Free : 24136 bytes (6BE9-CA31)
  17.       Data :  5640 bytes (CA32-E03A)
  18.  
  19.     Make a note of the following addresses:
  20.  
  21.       Code end address    :  6BE8\
  22.       Data end address    :  E03A-> these are used to calculate the
  23.       Data start address  :  CA32/  correct compiler end address
  24.  
  25.     the formula I use is as follows:
  26.  
  27.      Code End Address + (Data End Address - Data Start Address)+ 200h
  28.  
  29.     USING THE FIGURES FROM THE EXAMPLE LISTING ABOVE:
  30.  
  31.      6BE8h+(E03Ah-CA32h)+200h = 83F0h  <-- the magic number!!!
  32.  
  33.     Round the address UP to the next full page (8400h) and use this
  34.     as your compiler end address.   Set the HeapPtr variable 16 bytes
  35.     higher (840F) in the code and re-compile with the new end address.
  36.  
  37.     When run, your program will check to find the top of memory, set the
  38.     stack pointer (StackPtr) to just below the CCP, the recursion
  39.     pointer (RecurPtr) 1K lower than the Stack Pointer, and the Heap
  40.     Pointer to just after the end of the program data block.  This makes
  41.     ALL TPA available for use by the program.
  42.  
  43.     CREDITS:  James R. Shiflett of Stafford, Texas revealed this
  44.     technique to the world in the August-September issue of Micro-
  45.     Cornucopia Magazine (number 25, pages 74,75).  I applied the
  46.     technique to a number of programs I have here, and am satisfied
  47.     that it works without bugs.  The (so far) only PD program using
  48.     the technique (to my knowledge) is LCAT20, originally by Paul
  49.     Nance, recently revised by me.  LCAT20 seems to work in any size
  50.     TPA with complete success.  Thank you James R. Shiflett for
  51.     coming up with the fix for Turbo's most exasperating problem!!!
  52.  
  53. *)
  54.  
  55. {add this global variable declaration to your list of variables}
  56.  
  57. Var
  58.   MemTop : Integer Absolute $6;  {CP/M FDOS address, top of memory}
  59.  
  60. {after the first Begin in your main program, insert the following lines}
  61.  
  62. (* {<-- remove these after setting HeapPtr address}
  63.  
  64.   StackPtr := MemTop - $826;       {place Stack Pointer under CCP}
  65.   RecurPtr := StackPtr - $400;     {Recursive Stack Pointer 1k lower}
  66.   HeapPtr  := $????  ;             {16 bytes higher than compiler end address}
  67.  
  68. {remove these after setting HeapPtr address -->}  *)
  69.  
  70. (*Thats all there is to it!*)
  71. es h