Classic Computer Magazine Archive COMPUTE! ISSUE 74 / JULY 1986 / PAGE 10

Readers Feedback

The Editors and Readers of COMPUTE!

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

Safe Zones In IBM BASIC

Is there any way to store a few characters or flags in the IBM PC's memory that will survive the BASIC RUN command? I want my program to be able to "learn" as it runs and remember what it has learned each time it is run.

H. Beck

IBM BASIC's CLEAR command gives you the ability to create a safe area of RAM of almost any size. Besides deleting all variables, CLEAR controls the amount of memory available to BASIC. By adding a comma and a parameter to the CLEAR command, you can make the BASIC workspace smaller than usual, reserving the extra memory for yourself. The workspace is initially 65,536 bytes, but it's easy to reserve some memory at the top of that space. Use this format:

CLEAR ,workspace

where workspace is a number less than 65536. To calculate the correct value, subtract from 65536 the number of bytes you want to protect. For instance, the command CLEAR ,65280 reserves the last 256 bytes (65536 - 256 = 65280) of BASIC workspace for your use.

When you type RUN after a CLEAR statement like this, the size of the workspace is reset to its default but the data in the reserved area is not affected. As long as the next program begins with a similar CLEAR statement it can PEEK into the reserved area and find the values that the previous program POKEd there. Here's a simple program that stores some values in a 256-byte reserved area:

10 CLEAR,65280
20 FOR A=0 TO 255
30 POKE A+65280,A

After you run the program, enter and run this program to read the stored values back.

10 CLEAR,65280
20 FOR A=0 TO 255
30 PRINT PEEK (A + 65280)