in BASIC ROM:
|List of all BASIC keywords|
Type: Function General Programming-Syntax: FRE(<dummy argument>)
FRE accepts any numerical argument within the limits of the floating point format or any string argument, and returns the number of unused bytes of BASIC RAM. The argument has no influence on the result, and thus it seems this "function" is a system variable rather than a function per se.
FRE first performs a garbage collection to free up unused string memory. Then it calculates the RAM "gap" between the top of array memory (as indicated by the pointer at 49–50/$31–$32) and the bottom of string memory (pointer located at 51–52/$33–$34), by subtracting the former from the latter.
Although the "binary" result of this calculation is an unsigned 16-bit integer, the creators of BASIC V2 seeming saw fit to use a routine for converting the result back into floating point, which takes the result as a signed integer: As a result, if the amount of free memory exceeds 32767 bytes, FRE will return a negative number. To correct for this, add 65536 to the result if it comes out negative (see section Examples).
If the argument (either numeric or even a string) is missing or more then one argument is given the BASIC error ?SYNTAX ERROR IN line appears.
PRINT FRE(1) PRINT FRE(0)+65536
This example creates a user-defined function that fixes the "negative" results, and then uses it to report even the free memory well over 32767 bytes: