home *** CD-ROM | disk | FTP | other *** search
- (* TURBMEM.FIX by Jim Gronek, Phoenix, Az. 08/23/1985
-
- Module to allow Turbo Pascal programs to automatically adjust
- its Stack Pointer, Recursion Pointer and Heap Pointer to use
- all available memory in the TPA. Note that this routine will
- require that you compile your program twice, once without this
- routine to get the default code and data block sizes, and once
- with this module after adjusting the Heap Pointer address.
-
- To calculate the correct Heap Pointer address, compile the program
- with the default address used by Turbo in the .COM file mode.
- When the program has finished compiling, it will report statistics
- on the memory utilization, as follows:
-
- Code : 19487 bytes (1FC9-6BE8) {example settings only!}
- Free : 24136 bytes (6BE9-CA31)
- Data : 5640 bytes (CA32-E03A)
-
- Make a note of the following addresses:
-
- Code end address : 6BE8\
- Data end address : E03A-> these are used to calculate the
- Data start address : CA32/ correct compiler end address
-
- the formula I use is as follows:
-
- Code End Address + (Data End Address - Data Start Address)+ 200h
-
- USING THE FIGURES FROM THE EXAMPLE LISTING ABOVE:
-
- 6BE8h+(E03Ah-CA32h)+200h = 83F0h <-- the magic number!!!
-
- Round the address UP to the next full page (8400h) and use this
- as your compiler end address. Set the HeapPtr variable 16 bytes
- higher (840F) in the code and re-compile with the new end address.
-
- When run, your program will check to find the top of memory, set the
- stack pointer (StackPtr) to just below the CCP, the recursion
- pointer (RecurPtr) 1K lower than the Stack Pointer, and the Heap
- Pointer to just after the end of the program data block. This makes
- ALL TPA available for use by the program.
-
- CREDITS: James R. Shiflett of Stafford, Texas revealed this
- technique to the world in the August-September issue of Micro-
- Cornucopia Magazine (number 25, pages 74,75). I applied the
- technique to a number of programs I have here, and am satisfied
- that it works without bugs. The (so far) only PD program using
- the technique (to my knowledge) is LCAT20, originally by Paul
- Nance, recently revised by me. LCAT20 seems to work in any size
- TPA with complete success. Thank you James R. Shiflett for
- coming up with the fix for Turbo's most exasperating problem!!!
-
- *)
-
- {add this global variable declaration to your list of variables}
-
- Var
- MemTop : Integer Absolute $6; {CP/M FDOS address, top of memory}
-
- {after the first Begin in your main program, insert the following lines}
-
- (* {<-- remove these after setting HeapPtr address}
-
- StackPtr := MemTop - $826; {place Stack Pointer under CCP}
- RecurPtr := StackPtr - $400; {Recursive Stack Pointer 1k lower}
- HeapPtr := $???? ; {16 bytes higher than compiler end address}
-
- {remove these after setting HeapPtr address -->} *)
-
- (*Thats all there is to it!*)
- es h