Programming Techniques - Dropping PAGE to increase BASIC memory =============================================================== J.G.Harston, 18-Sep-1997 Programs should adapt themselves to use the amount of memory available by checking how much memory is between LOMEM and HIMEM, for instance: max%=(HIMEM-LOMEM-500)DIV4:DIM array%(max%) will define an array of a size that will it into the available variable space, leaving 500 bytes left over for other variables. Note also that you should always compare HIMEM to LOMEM, not to TOP. By default LOMEM is at TOP, but the variables can easily be put elsewhere, TOP is the complement to PAGE, LOMEM is the complement to HIMEM. Sometimes a program has to have a certain amount of workspace, and the usual way to do this is to lower PAGE. However, You mustn't just force PAGE down to an arbitary address that you think is best, you should move PAGE down only if it needs to be, and only by the amount that is needed for the program to run. The best way of doing this is to start the program with the following: MODE&87 IF HIMEM<&8000:A%=HIMEM-LOMEM-sizeneeded:IF A%<0:PAGE=PAGE+A%:CHAIN$&600 replacing sizeneeded with an appropriate amount for the program, and ensure you use shadow screen modes (&80+n) in the rest of the program. Then, PAGE will only be forced down if and only if it actually needs to be, and only by an amount that it needs. This starts by selecting the smallest possible screen mode, and if that results in program space being used it calculates if PAGE needs to be dropped, and if so it drops it by the required amount and reCHAINs the program by using the contents of string buffer that has just been used to load the program. Some experimentation will be needed to work out the sizeneeded value. One way is to start with &4C00 and progressively add &100 until the program has enough memory to run. or.... Find a value of PAGE where your program works with HIMEM at the non-shadow screen value for the screen mode the program will use. In testing you may need to temporarily put HIMEM=&3000 at the start of the program to force it to work as though there is very little memory available. Then use PRINT ~(&7C00-TOP) AND &FF00 and this should be the value to use for sizeneeded. If this is not enough, then usually just adding another &100 to sizeneeded will do. You will then end up with something like: MODE&87:IF HIMEM<&8000:A%=HIMEM-LOMEM-&4E00:IF A%<0:PAGE=PAGE+A%:CHAIN$&600