Getting Started with Beta BASIC

Author(s): Robert Hartung
Publication: SyncWare News
Pub Details: SyncWare News v5 n5 (Volume 5, Issue 5)
Date: May/June 1988
Pages: 18-19

Recently I have received several requests from BETA BASIC users for some suggestions on how to use its utility functions and programming features. Some who were subscribers to CTM in 1986 may recall a series showing comparative listings for BB and the QL which appeared in the March through November issues. I will try not to duplicate anything in SWN I submitted then or since to other publications. This allows more material to be made available on the subject overall as well as observing proper editorial ethics.

In the Beginning…

Perhaps the best place to start is with a brief overview of BB and some of its features which make it useful for editing and manipulating listings and data, either in BB programs per se or in T/S (TS2068) or SP (Spectrum) listings loaded in with BB in-residence. Spectrum mode is required because it is written to utilize many ROM routines which are found at different addresses in the Spectrum than in the TS2068. It is a totally SW (software) extension to Sinclair Basic and is transparent in use, i.e. all of the Sinclair commands and syntax are retained while adding over 100 new and enhanced commmands and functions that utilize a very similar syntax and entry system. Many of these provide from 2 to 10 optional formats, giving it even greater power and flexibility. A version 4.0 written specifically for the 128K Spectrum has all the features of version 3.0 for 48K, plus almost instant RAM-disk access, interrupt-driven 3-channel sound, and much faster line-graphics and FILL in any texture or color.

At first thought it might seem limitation to the 22K-byte free memory remaining with BB in residence would impose serious restrictions. Actually, however, BB calls its own MC routines with commands using only a few bytes that can replace hundreds of bytes of Basic listings, with much faster processing. Listings and data saved separately in T/S or SP mode may be loaded into BB, edited, sorted, or otherwise manipulated with BB, and then saved again for use with normal T/S or SP programs. Thus anything that will fit into the normal 48K memory can usually be processed by BB. Of course a Microdrive, Wafadrive, or DOS does this much more quickly and easily. BB will work with a Spectrum-compatible DOS but not with T/S memory-extension cartridges.

Array Usage

As an example of the time and memory efficiency of BB, suppose we had a large alphanumeric array such as a$(400,20) that we wanted to sort and re-order. Instead of a lengthy Basic routine, the listed or direct BB command SORT a$() would do the job in 3 seconds. INVERSE SORT a$() would reverse the order. The re-ordering could be done either in a program that contains the data, or on data loaded in with BB in-residence. This may turn on some light bulbs of your own as to possibilities for other uses. A note of caution when using BB with Oliger SDOS (and perhaps others): During the SORT function the “B” board must be switched off to avoid a conflict with NMI that will cause a crash. This seems to be the only serious DOS conflict I have found so far.

When using an array such as a$(150,64) to hold text lines in a Basic word-processing program, the command EDIT a$(n) will bring that entire line back into the editing screen for any desired changes, rather than having to type it all in again. (CSIZE 4,8 gives a 64-column display and listing.) Another form of the EDIT command allows any line of a listing to be brought into the editing screen by simply preceding the line number with a zero and keying ENTER. The rest of the displayed listing is not disturbed until the edited line is entered again. (LIST and LLIST allow selection of listing blocks or single lines.) The cursor may be moved vertically as well as horizontally through the editing screen for both these EDIT modes. While not quite as handy as the full-screen editing provided by Toolkit on the QL, this certainly is a vast improvement over the T/S editing facility. By the way, the Spectrum doesn’t make those annoying balks like the T/S does when deleting line numbers, colons, or THEN.

More Commands

Other useful editing tools are the AUTO, RENUMber, SPLIT, JOIN, and TRACE commands. AUTO will start at the specified line number and step increment, or 10 if neither are specified. Literal numbers used with GO TO, GO SUB, RUN, LIST, LLIST, LINE, ON ERROR, ON, TRACE and DELETE will be correctly altered by RENUM, but not expressions or calculated values such as GO TO 10*(n=5), which will be listed as “Failed at line n.” RENUM * 10 TO 100 LINE 500 will make a copy of lines 10-100 starting at line 500, while RENUM 10 TO 100 LINE 500 will move that block of the listing so it starts at line 500.

If a multi-statement line is brought into editing mode, the <> symbol inserted before the first non-space character in any of the statements will split the line at that point. The first portion will be re-entered into the listing with its original line number while the rest of the line will remain in editing mode to be given a new line number. If the JOIN command is keyed in, the line following the one indicated by the listing cursor will be joined to it as one line. The use of the TRACE command as a debugging tool is described in more detail in the manual than we have room for here.

Another form of the JOIN command, eg: JOIN a$ TO b$, allows concatenation of strings or arrays in memory, even when only one byte over their combined length remains free. If you have an array a$(100,10) that you need to extend to a$(100,20) then DIM b$(1,20): JOIN a$ TO b$: DIM a$(1,20): JOIN b$ TO a$ will pad each string in a$ to 20 characters, without data loss. If we wished to insert the entire array a$ into b$ so that the first inserted string is the 4th string in the enlarged array b$ then we could use JOIN a$ TO b$(4). One use of this might be in an editing routine to shuffle text around in a word-processing program. The COPY command is very similar in syntax and function but does not remove the copied string from memory as JOIN does.

The INARRAY function searches a specified string array for a target string and returns the number of the first array-element in which it is found, or zero if not found. INSTRING does the same for a single-element string such as a$ or a$(1000) except that the character-position is returned. The # “don’t care” may be substituted for one or more characters in the search-string. Thus PRINT INSTRING(1,a$,”SM#TH”) would find SMITH, SMYTH, SMATH, etc. in the target string, or in an array if INARRAY were used. Again this could be used with DELETE and JOIN to create a search and replace routine for our hypothetical word-processor.

I hope all this has been more informative than confusing and perhaps has created some interest among those who are not already Beta Basic users. If sufficient reader support is indicated, next time we will take a look at actual routines and procedures using some of the many other BB commands. It would add a great deal to the interest and usefulness of this series if users cared to share procedures they have created. QL procedures also can usually be easily translated to BB and vice versa.

Both Beta Basic 3.0 for 48K Spectrum/emulated TS2068 and BB 4.0 for 128K Spectrum are supplied on one cassette for 15.95 pounds sterling by Betasoft, 24 Wyche Ave., Kings Heath, Birmingham B14 6LQ, England. BB 3.0 by itself is a little less because of its smaller manual. MasterCard is accepted by them for easier currency exchange. I have available a 20K-byte demo giving working examples of about 85 BB commands and functions for $5 U.S. to cover the cost of the tape, packaging, S&H. Please note that the version of Beta Basic used by permission of BetaSoft to drive the demo will NOT work with any other listings, and requires Spectrum mode. It may also be used as a tutorial when used with the normal version of BB 3.0.

NOTE: the exchange rate varies from day to day, of course. As the author notes, the use of a MASTERCARD would save you the trouble of buying foreign exchange when you place your order. However, it might help your decision making to know that the exchange rate at the time this article is being prepared for publication, is

1 pound sterling=$1.80 (approx.)

This means that the BB 4.0 version would run a little less than $30.