in BASIC ROM:
|List of all BASIC keywords|
Type: Function General Programming-Syntax: FRE(<"Dummy" numeric variable>)
FRE accepts any numerical argument within the limits of the floating point format, 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 "gap" in RAM between the top of array memory (as indicated by the pointer at 49–50/$31–32) and the bottom of string memory (as per the pointer 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 is 32 kB or more, FRE will return a negative number. To correct for this, add 65536 to the result if it comes out negative.
If the numeric argument is missing 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 the well over 32 kB of free memory: