Optimizing BASIC on the 2068

See all articles from Update July 1994
Author(s): David Lassov
Publication: Update Magazine
Pub Details: Update July 1994
Date: July 1994
Pages: 25-27

Systems-Oriented Languages, CORP
2590 N. Jordan DR
Tucson AZ 85745-1132
602 884 7667 (voice)
602 882 0388 (data )
5 7 94

Frank Davis
Editor, UPDATE Magazine
513 E. Main
Peru IN 46970

Dear Frank :

In the April, 1994, issue of UPDATE Magazine, there is an interesting article by Albert F. Rodriguez, entitled “ZX-81 TIC-TAC-TOE,” interesting , not so much for the game, but for what it says about optimizing BASIC code on the ZX-81. For, we have just about finished reworking BASIC code by Bill Jones on the TS2068, and some contributions are just begging to be mentioned, about optimizing 2068 BASIC code.

For example, there are a lot of FOR-NEXT loops, which are burdened with the extra time it takes to POKE 23692 with -1, or 255, or whatever. If these POKEs are changed to “POKE 23692,0”, then they completely disable the interrupt facility, that prompts for “SCROLL?”, AND they can therefore be pulled out of the loop, moved ahead of the loop, and executed ONCE PER LOOP, rather than ONCE PER loop CYCLE.

Similarly, Bill terminates many of his loops, by including an “ONERR GOTO” statement, and these can be pulled out of the loop, put ahead of the loop, and executed ONCE PER LOOP, rather than ONCE PER loop CYCLE. Of course, orders-of-magnitude improvement in processing speed result from this alteration of the loops involved.

We consider the Timex 2068 to be a MEMORY-BOUND data processor, and Bill gets around this by several useful techniques. First, he seems to be the first program developer to incorporate on a wholesale scale the BASIC operations, utilized to access the new disc operating systems. His flagship program, the word processor SMARTEXT was developed in the early 80’s to occupy the programmable RAM of the 2068, and he greeted the appearance of JLOdos and LKdos, by fragmenting SMARTEXT into a suite of little subroutines, which accomplished the same operation, but DELETEd themselves upon completion, in order to MERGE the next operation from disc.

The suite is called DAISY and coordinates about 100k of CODE, all sharing 37k of RAM. But, as Larry Kenny indicates, “…there will be noticeable difference in the speed of a merge compared to a load.” Thus, we have seen fit to break out the four MERGEable incarnations of DAISY into four LOADable versions of Daisy.

Another device, that Bill uses in his EXTRA-MEMORY PROGRAMMING, besides DELETE and LOAD, is the variable file of the 2068. First, he sets all the constants into the variable file, and he uses the constants, by refering to their variable name. He gains several benefits here with only two costs. The constants refer to unique locations throuhout the program, no matter how many times they be referenced. The entire variable file is SAVEd and LOADed, completely changing the configuration of the operating program by menu selection. The net gain in available memory is “memorable”, to say the least. We typically save 10000 bytes of RAM, by refering to only 4000 bytes of predefined constants.

But, there are some extra memory cycles involved, so that a really tight loop often requires the actual numbers, in order to meet its timing criterion. Similarly, an excess of string operations can slow things down. Apparently, the 2068 BASIC regenerates storage for its strings upon every execution of the instruction involved. While this accounts for the 2068’s advanced string manipulating capability, it is costly in machine cycles and must be used judiciously. However, functions can be very useful, when using strings. For example, we never use strings, when we can get away with evaluating their LEN, CODE, or VAL.

The second cost, associated with Bill’s memory-saving technique of refering to constants by their predefined names is the usual tragedy, resulting from inadvertant use of RUN, in order to start a program. The whole variable file is CLEARed. It must then be RESET, which is no problem, should you have the foresight to store a VARSET program. VARSET can be LOADed, RUN, and DELETEd. Then, the program, which uses the variable file, set by VARSET, is simply MERGEd in from disc, right over the variable file.

And, lastly, there is the issue of SELF-DOCUMENTING code. After a year away from a program, it is easier to recall what (CODE”8″-CODE”0″) stands for, rather than (CODE”8″-48). So, after all,this is just another application of Chapter 3, “SAVING TIME AND SPACE” by Randle Hurley, as mentioned in Mr. Rodriguez’ nice article. It applies to the TIMEX-SINCLATR 2068. Just think : Only the QL by Sir Clive does not use the Z-80 microprocessor. the ZX-80, ZX-81, TS2068, and Z88 differ fundamentally only in the OPERATING SYSTEM. But, what differences!!!!

We are anxious to use Mr. Impellizzori‘s new BBS in Detroit Michigan. It is for Sinclair freaks like us; is run on a QL; is called QBOX-USA; and, is intercontinental/international in scope.

As a matter of fact, we feel that Frank Davis and Paul Holmgren have an opportunity to bring the 2068 into the 21st century, by developing, supporting, and making available telecommunications Hardware and Software for the 2068, as cheap and flexible access to the coming information super-highway.

KEEP
TIMEX’n

Thanks again,
[signature]
David E. Lassov