You Are Wasting Your Arrays / Rumors
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
memory. But how does one set aside space for these arrays? We can't put them just anywhere. They might be overwritten by this program or system. The trick is to use the DIM statement, something we were trying not to do. However, we are not defining these arrays as numerical arrays. We're going to set them up as strings! That's right, you heard me the first time. We are defining the arrays as strings, but we are surely not going to use them this way.
There is an interesting function available in ATARI BASIC. It returns the address of a string array. Does this give you any ideas? We dimension a string array, and use the ADR(A$) function to be able to PEEK and POKE into it. The starting addresses in the preceeding examples are replaced with ADR(string array). Then, X=PEEK(1536+N) becomes X=PEEK(ADR(A$)+N) AND POKE XYZ+1*6+J,X becomes POKE ADR (XYZ$) +1*6J,X. After the string is defined, we replace all references to the starting address with the ADR function and the string variable name.
You might be wondering why we don't assign a variable to the address of the string. To let XYZ=ADR(XYZ$) seems sensible. After all, it cuts down on calls to the ADR function. This line of thinking makes a lot of sense, but it can cause problems. This has to do with the fact that string variable addresses can change as a program is running. This seems to happen only when a new numeric variable is encountered in a program, and BASIC has to make room for it. This is accomplished by pushing all the string space farther up in memory. It is safer to have the computer constantly recompute the string addresses.
"MOIRE" GRAPHICS DEMO
Note: hit any key to stop
10 DEG
20 A=INT(1.9*160)
30 GRAPHICS 8+16
40 SETCOLOR 2,0,0
50 FOR I=O TO 160 STEP 5
60 B=INT(I/2)
70 COLOR 1
80 PLOT 0,B
90 DRAWTO 1,160
100 PLOT A,B
110 DRAWTO A-I, 160
120 PLOT 0,160-B
130 DRAWTO 1,0
140 PLOT A,160-B
150 DRAWTO A-I,O
160 NEXT I
170 IF PEEK(764)<>255 THEN END
180 GOTO 170
RUMORS...
Have You Heard The One About.
... rumors about a graphics chip for the ATARI 825 printer
... a multi-player Star Raiders with advanced capabilities: landing on asteroids to partially refuel and swooping
down into planets atmospheres and bombing alien cities
... the release later this year of a voice synthesizer and voice recognition system by ATARI
... a new operating system: with a 96K addressable memory bank
... a screen dump cartridge for the 800's right hand slot; prints what's on the screen to hardcopy
... Telelink 11; "a smart terminal emulator" with graphics capability and upload/download abilities
... from Microtek: an EPROM burner (make your own cartridges), A/D & D/A converters (hook your ATARI up
to outside sources - you can control things), BSR unit (have your ATARI turn lights in the house on and
Off,
etc.)
... 80 column screen formatter!
... a word -processor on a ROM!
... Galaxian for the ATARI!
... an ATARI 400 with built-in modem - with no internal microprocessor (to be used as a
dumbterminal)
... ATARI's are now being used in the CUBE system in Columbus Ohio. It is part of the two-way television
communication system.
... And the ATARI Program Exchange: This department will handle the marketing of third party software and
also sell software from ATARI under this name.
Programs to be released initially:
Adventure games
Avalanche
Baseball
Cross Referencer
Forth Language
Star Trek game
Sound Development System
Othello
Turtle Language ... and much more.
Digitized by CyberRoach Publishing for CyberRoach’s Digital A.N.A.L.O.G. Archive; restored here with permission.