Dense Pack BASIC

Authors

Publication

Pub Details

Date

Pages

See all articles from The Plotter v5 n6-7

Reference: “Speed Up Basic‘ in Plotter (4/87). The use of Boolean logic with BASIC has not been covered well in computer literature. (Ed. Boolean Logic, named after George Boole, who defined an algebra of logical operations, such as AND, OR, and NOT, on the two values true and false). The Timex Sinclair computers are very accommodating to Boolean logic. Almost any Boolean expression is acceptable when enclosed in brackets after any key word. Not only does such logic expressions speed up BASIC programs, but memory usage for such expressions can be reduced as much as 70 per cent as compared with conventional BASIC expressions. Moreover, the use of Boolean can greatly reduce the need for multiple branching to sub-routines. Entire packages of sub-routines are contained in one line of programming. Such packages may contain an elaborate chain of IF THEN conditional statements, action programming, print statements, computations, GO SUBs and Machine code calls. TS-1000 users can do in one line what would require 10 or more lines of programming to accomplish, while TS-2068 users can pack in much more.

Enclosed are excerpts from one of my software manuals that explains some of the applications and rules of using Boolean Logic in BASIC programming. These are applicable to all computers, but especially suited to the TS-1000 and TS-2068. “Dense Pack” employs other memory saving techniques to become a means of incorporating more functions in a BASIC program than would be possible using conventional methods of programming. In fact, the use of Dense Pack reduces memory requirements to that required for a Machine Code program that accomplishes the same functions, while retaining the user friendliness of BASIC. While speed of operation is considerably improved, it does not match the speed of Machine Code in execution.

Sincerely,
Bill Jones

“Dense Pack” is an acronym, coined by yours truly, to give a name to a group of programming techniques. Dense Pack is inovations that use memory saving techniques and Boglean exeressions to save tremendous amounts of program memoy. Despite the bank switching capabilities of the TS-2068, most users do not have extra memory, and if such extra memory is aboard, the Machine can only address one bank at a time. So, we are stuck with a FREE RAM of 38652 bytes. This limitation requires extra ordinary techniques to pack in such comprehensive works as Smart Text. I will devote enough space to the subject to give you a start off. Then it should be fun to see what you can make of it for your own programming. Also, this will help when you are trying to decipher the mixture of chinese and aribic of My program lines. While programming the first version of Smart Text, I ran out of FREE memory and had no room left for Data Files. Now that wouldn’t be much use to anyone, would it! The application of Dense Pack cut the program length by half and allowed many more functions to be added.

We start kinda like the daughter’s wedding, with something old, something borrowed, and something new. You have read that less memory is used when variables are used for numbers. For short programs, it is not worth the effort. However for long programs such as Smart Text, it is well worth the effort to spend some memory to establish a table of variables to use over and over. You’d be surprised how many times a long program uses the numbers 1 through 20. Dense Pack sets up these numbers in a ‘pseudo hex’ table. The system lends itself to ‘counting on your pinkies’ as does most folks, even Math professors. It goes like this: oo=0, oa=1, ob=2, oc=3, through ou=20. Soon one’s mind adjusts to pseudo hex, and one finds oneself counting on fingers, using “a, b, c, through u. Now I could have used “Seminole hex”, where 1, 2, 3, 4, 5, IS ‘umi, coli, chani, coi, chocki”, but most folks would have difficulty with Indian counting. Throughout the programming, this pseudo hex table is used to save lotsa memory. Rhen you see an “o° variable, you can count up the alphabet to interpret the number.

Dense Pack uses Boolean expressions instead of “IF THEN” expressions. The results are the same, but many lines of programming are eliminated. Would you believe a dozen “IF THEN Conditions” in a single line? Such a line would save about 75 per cent of memory used for conventional programming of the 12 IF THENs. Lets examine a typical “DENSE PACK” group of IF THEN conditions after a menu that has 9 options. (2120 GO TO (z(oa OR z)oi* VAL “2002”+(z=oa)*ip+(z=ob)*d+(z=oc) * ml+(z=od)* VAL “2110”+ (z=oe)* VAL “4055”+(z=of) *ba+(z=og) *te+(z=oh) *rp+(z=oi) *fm). Note the pseudo hex vars “oa thru oi”. Then some line numbers are also represented by vars. But the big picture is the 10 IF THEN conditional that are stuffed into one line of programming. This eliminates nine lines of programming that would normally be required. Also the method saves 75 per cent of the memory required for conventional programming. The “IF THENs” are implied in each of the expressions enclosed in brackets. The CPU trips through the whole tulip patch and evaluates all 10 of the IF THEN conditions.

DENSE PACK RULES: Yes, there are rules to observe. You must account for ALL POSSIBLE conditions. This line would work: <10 PRINT (“Hello” AND y=1) + (“Good Bye” AND y=2)›. BUT- if y should be something else than 1 or 2, the CPU would take off looking for what to do. Since it could not find the solution, the last line of the whole program would likely be executed. A safer way of expressing would be: ‹10 PRINT (“Hello” AND y(2) + (“Goodbye” AND y>1)). Now here is an example of Dense Pack mixed with a conventional expression: ‹10 IF Z=1 THEN GO TO (b=1) *100+(b=2) *200+(b<1 OR b)2*10). Do You see the the protective measure in the last bracket? Another rule is, the factors within the brackets cannot be mixed. This line would not work: <10 GO SUB (a (2)*200+(a)1) *300: GO TO (b < 2)*400+ (b>1) *500>.

Products

 

Media

 

Image Gallery

Source Code

Scroll to Top