Now, I hope you don't think that I'm saying not to buy more memory. There are many programs coming out that will require an increase in RAM, or at least will benefit from it. However, I am saying not to add another memory board just to make up for poor programming techniques. The memory saving methods used here will show you how to cut down some of that wasted space by as much as 80% and may even speed up program execution, but first a few basics.
Numbers in ATARI BASIC are stored in six consecutive bytes in the computer's memory by a method known as BCD (Binary Coded Decimal). This procedure packs real numbers into the six memory locations, two digits per byte. Five of these six bytes contain the number and sign, while the sixth holds the value for the exponent. This is fine if you are using numbers like 194753 or 12.774 or even 12E22. But if you are using only integers in your array, and they just happen to range in value from 0 to 255 inclusive, then they can be stored easily in one byte locations.
The most convenient place in memory to put these values is a 256 byte space which ATARI has set aside for your own use. This block of RAM starts at memory location 1536 ($600 for you machine language programmers). Access to these locations can be gained in BASIC by using PEEKs and POKEs. To store a number X in the N'th element of such an array, the statement POKE 1536+N,X is used. To get a value out of this array we use the statement X=PEEK(1536+N). This method works, and it even runs faster than dimensioning an array. Don't forget to allocate space for each and every array. It would not be good to have them overlap each other. The best way to do this is to assign a different variable to each starting address. If array HOR is to have 10 elements, and array VER is to have 5,then the starting addresses would be HOR=1536, VER=+10, NEXT=VER+5. Done this way, the arrays will never meet each other. To store X in the 3rd element of VER, you would type the statement POKE VER+3,X. The offset from the base address of an array starts with zero, just as if it were dimensioned. Now, what if the arrays need more than 256 elements, or the arrays need more than one dimension. Well, just keep on reading. The best is yet to come.
In ATARI BASIC an array can have up to only two dimensions. This is a limit put on BASIC by the people who originally wrote it. BASIC takes the two index variables passed by the statement accessing the array, and by a series of multiplications and additions, arrives at the address of the variable stored in the array. Since your program is now to do all this work instead of BASIC, we have effectively cut out the middle man, namely the programmer who gave us the two dimension limit. Since we are now writing the array access software, we can set our own limits.
As an example, we will set up an array of size 5 by 9. Normally, we would type DIM XYZ(5,9) which would allocate 360 bytes to the array. Since we want to keep litter in its place, we are going to use the alternate method. The first dimension contains 6 elements (0-5) and the second 10 (0-9). Space must be set aside in memory (6 times 10 = 60 bytes) for the array. To access a value in the array, use this formula: (<array address > + <1st index>* <2nd's limit> + <2nd index)). To read the (2,3) element of the above array, type A=PEEK(XYZ+I*6+J,X. It is really very simple. To handle a three dimensional array, we build on the two dimensional array. The formula in this case is: (<array address> + <1st index > * <2nd's limit>* < 3rd's limit> + (2nd index)* <3rd's limit> + <3rd index). In an array TEST(4,4,4), which has really 5*5*5 elements (0-4); to get the (X,Y,Z) value you type A=PEEK(TEST+X*5+Y*5+Z). Simple, it is not. You can create 4 or 5 dimensional arrays this way. There is really no limit to it.
I found it to be easier if variables are defined that contain the limits of the compacted arrays. These variables simplify the calculation of the address offsets. The main reason to use variables for limits is that at times the number of elements in an array is not known until the program is executing.
This seems as good a time as any to issue a warning. You have to be careful that the indexes used by your programs do not exceed the defined limits. If the indexes should go out of bounds then the integrity of your data will be lost. Data may be written to or read from the wrong position, or to and from the wrong array. If you start getting eroneous results, it is most likely for this reason.Now, what do you do if the array or arrays use up more than the 256 bytes at address 1536. They will have to be put someplace else in the computer's