Don Lambert wrote stating that being a less experienced programmer he could not understand why I used statements with RND, VAL and CODE in them. The answer, of course, is to save RAM space. Just a couple of bytes saved can sometimes save a whole disk track of 5090 bytes! My favorite example is opening up stream #4 to access LKDOS calls because PRINT # 4 is supposed to be easier to type [less key strokes] than RAND USR 100″. [page 11 of the V3 manual] Larry Kenny suggested that it uses less RAM space in a program. The fact is it uses up MORE RAM space! (My real problem with opening stream #4 is that it is also the stream assigned to my ZEBRA Talker.)
To illustrate the RAM savings, let us consider a short program to load LogiCall. Sit down at your machine and do the following:
Turn on your TS2068 and type PRINT FREE <ENTER> . You get 38652. This is our free RAM space. Now enter the following two lines:
10 RANDOMIZE USE 100: OPEN #4,"dd"
20 PRINT #4: LOAD "L.B1"
Now type PRINT FREE <ENTER>. You get 38600. Strange, 29 key-strokes used up 52 bytes!
Now EDIT the lines and put VAL with quotes around the 100 and the two 4s. The program now reads:
10 RANDOMIZE USE VAL"100": OPEN # VAL"4", "dd"
20 PRINT # VAL"4": LOAD "L.B1"
Now type PRINT FREE <ENTER>. You get 38609. Strange, you just added 9 keystrokes to the program and saved 9 bytes of RAM!
Now for the ultimate RAM saving trick. Most numbers over 31 can be expressed in the program as CODE. Let’s change VAL”100″ to CODE “d”, the two are equivalent. (See page 242 in the TS2068 manual or type ‘PRINT CODE “d” and check the response.) The program now reads:
10 RANDOMIZE USE CODE"d": OPEN # VAL"4", "dd"
20 PRINT # VAL"4": LOAD "L.B1"
Now type PRINT FREE <ENTER>. You get 38611. Losing the two zeros bought us two bytes. Notice that the following statements all mean the same thing.
RANDOMIZE USR 100
RANDOMIZE USR VAL "100"
RANDOMIZE USR CODE "d"
But what about OPENing stream #4 to save RAM space. Type in the program:
10 LET h=CODE "d"
20 RANDOMIZE USR h: LOAD "L.B1"
Now type PRINT FREE <ENTER>. You get 38624.
Both programs will LOAD LogiCall but the busiest stream #4 call uses 41 bytes while the USR call uses only 28. Also, for the record, RAND USR h is six bytes shorter than PRINT # 4 and just as easy to type, so
WHY OPEN STREAM #4?