Classic Computer Magazine Archive COMPUTE! ISSUE 50 / JULY 1984 / PAGE 133

Program Conversion With Sinclair BASIC And TI BASIC

Julie Knott and Dave Prochnow

Program conversion between BASIC dialects is often easier than imagined. This tutorial demonstrates the compatibility of TI BASIC and Sinclair BASIC and includes helpful tables and sample conversion programs.

Program conversion can be an easy and convenient operation. Virtually every home computer uses BASIC, which, because it's easy to learn and to manipulate, is ideal for ready-made language conversion. However, no two BASICs are created equal. For many years the industry's standard was Microsoft BASIC, then different dialects began to emerge. Manufacturers would use the Microsoft format and introduce nuances and subtleties in the structuring, labeling each of these alterations an "improvement" of BASIC. But many were only changes in the protocol—the manner in which a command is expressed. And it becomes relatively easy to convert BASIC dialects if the major differences are in protocol or syntax.

Two versions of BASIC which lend themselves to such a program conversion are Sinclair BASIC and TI BASIC. Sinclair BASIC, used in the Timex/Sinclair-1000, is unique in that all keywords are single-stroke entries. For example, the P key stands for the PRINT command. (The use of a touch-membrane keyboard dictates this procedural necessity.)

Texas Instruments TI-99/4 and 4A use TI BASIC, which is more conventional in that each individual letter has to be typed—PRINT would require five keystrokes.

There are only slight variations between Sinclair BASIC and TI BASIC, but their similarities allow for easy program conversion. By studying which statements and commands are equivalent for both BASICs, and what substitutions are necessary, program conversion can be relatively simple. Also, you can virtually double your software by translating programs published for the other machines.

For the sake of brevity, the following glossary does not contain all of the keywords in Sinclair BASIC and TI BASIC—only those words which are confusing, complicated, or not directly translatable have been listed. For a more complete listing, consult the appropriate user's manual.

Sinclair BASIC

AND — a logical operator, often used in IF-THEN statements

ACS — function that gives the arc cosine of an angle in radians

ASN — function that gives the arc sine of an angle in radians

AT — used in a PRINT statement to give a location at which to PRINT

BREAK — stops program execution, key activated and may not be included as a command in a program

CLEAR — deletes all variables from memory CLS — clears the screen

CODE — a string function used to obtain the numeric value of a given character

CONT — resumes execution of a program following a report code

COPY — copies the contents of the screen to printer

DELETE — erases keywords and characters while programming

FAST — fast mode, a time-saving mode for increased RUN speed

FUNCTION — function mode GRAPHICS — graphics mode

INKEY$ —used in IF-THEN statements as a conditional statement, executes exclusive of ENTER

LLIST — lists the contents of a program listing to a printer

LOAD — loads a prerecorded program from cassette tape to the computer's memory

LPRINT — PRINTs to printer

NOT — inverts the truth value of an expression

OR — a logical operator, used in conditional statements

PAUSE — creates a time delay while the program is RUNning

PEEK — gives the value of the byte at a specific address in memory

PI — gives the value of PI

PLOT — draws a pixel at a given location

POKE — puts a numeric value into memory at a specific address, erasing the previous one

SCROLL — scrolls the screen up one line, eliminating the top line

SLOW — slow mode, the standard operating mode

UNPLOT — erases a pixel at a given location

USR — calls a machine language routine at a specific memory address

TI BASIC

APPEND — an open mode, allows data to be added at the end of the existing file

ASC — ASCII value or character code

BASE — option base

BREAK — sets breakpoints in a program, used for error checking

BYE — erases memory, returns to title screen

CALL — special subprogram to obtain color and sound

CLOSE — closes the association between a file and a program

CONTINUE (CON) — continues a program after a breakpoint

DATA — stores data

DEF — defines user-established functions in a program

DELETE — removes a program or data file from a filing system

DISPLAY — prints on screen only

ELSE — conditional part of IF-THEN/ELSE statement

END — terminates program, similar to STOP

EOF — End-Of-File, determines if the end of a file has been reached on an accessory device

FIXED — files with a specified length, used with RELATIVE or SEQUENTIAL

INTERNAL — file type recorded in machine language

NUMBER (NUM) — automatic line number generator

OLD — loads a previously SAVEd program

ON — a conditional numeric expression, used with ON-GOTO or ON-GOSUB

OPEN — prepares to use data files stored in accessory device

OPTION — option base, sets lower limit of array subscripts to 1 instead of 0

OUTPUT — transfers data out of a program

PERMANENT — file life

POS — position

READ — reads data in DATA statements

REC — points to a specific record in a RELATIVE file

RELATIVE — defines a file with FIXED

RESEQUENCE (RES) — reassigns line numbers

RESTORE — identifies which DATA to use with the next READ

SEG$ — string segment, substring

SEQUENTIAL — defines a file, used with FIXED or VARIABLE

SUB — part of GO SUB

TRACE — outlines the order that statements will be performed when the program is RUN

UNBREAK — removes breakpoints

UNTRACE — cancels TRACE

UPDATE — an open mode, for reading and writing into files

VARIABLE — defines a varying length file, used with SEQUENTIAL

Special Subprograms Used With Graphics And Sound In Tl BASIC

Each subprogram is preceded by CALL (for example, CALL CLEAR)

CLEAR — erases the entire screen

COLOR — specifies screen character colors

SCREEN — changes screen color

CHAR — defines user-special graphic characters

HCHAR — places a character and repeats it horizontally

VCHAR — similar to HCHAR except repetition is vertical

SOUND — produces tones and noises of different duration, frequency, and volume

GCHAR — reads a character anywhere on the screen

KEY — transfers character directly from keyboard to program without ENTER

JOYST — inputs data with remote controllers

Easy Conversions

Many of the commands and statements of these two BASICs are directly translatable. Table 1 shows the direct BASIC equivalents for Sinclair BASIC and TI BASIC. The only major differences between these two dialects are in their nomenclature.

Several dialects of BASIC have an ON-GOTO statement expressed as:

ON x GOTO w,y,z

where x is the value of a numerical expression and w, y, and z are line numbers. This statement is available in TI BASIC, but not in Sinclair BASIC. Through the use of conditional expressions, the Sinclair BASIC substitution is:

GOTO (w AND x = l)+(y AND x=2)+(z AND x = 3)

The operators AND and OR would make this possible.

The translation of many program lines requires only the replacement or substitution of a word unique to that particular BASIC. Several of the more common functions and statements are evaluated in this manner in Table 2. The following Sinclair BASIC line will await the pressing of the Y key, exclusive of ENTER:

100 IF INKEY$ < > "Y" THEN BOTD 100

To perform the same statement in TI BASIC, replace INKEY$ with the KEY subprogram, as follows:

100 CALL KEY(0,K,Z)
110 IF KO89 THEN 100

The main difference is in the structuring. The KEY subprogram (subprograms are obtained with CALL) uses three variables to establish where the key is originating, its ASCII code, and its status. In this example the ASCII code of 89 represents the Y character.

TI BASIC has the ability to store expressions and assign values to these variables with the statements DATA, READ, and RESTORE (see the glossary). Vast arrays can be developed and initialized with this method. Sinclair BASIC is not directly convertible with DATA, READ, and RESTORE. A large battery of LET statements could crudely handle the data. Alternatively, a properly DIMensioned INPUT statement allows the creation of such an array. Upon completion, the INPUT statements are removed and a GOTO command is used for program starting (RUN erases the variable array).

String Handling

Strings can be equally bothersome. Slicing will supply usable substrings in Sinclair BASIC. A string expression's parameters govern the start and finish of the slice. No special statement is necessary:

A$(x TO z)

with x representing the starting number and z the finish. For example:

"COMPUTE" (4 TO 7) = "PUTE"

The statement SEG$ (A$,x,y) in TI BASIC has the same result, but, again, with different nomencla-ture. X is the number of the start for the substring and Y is the length of the substring. For example:

A$ = "COMPUTE"
SEG$ (A$,4,4) = "PUTE"

While string slicing is easily translated, the TI BASIC user-defined function is not. DEF allows the definition of functions within a program.

DEFX$ = "Y"

The string function's name is X and the string expression is Y. VAL and string variables can be user-defined in Sinclair BASIC.

LETX$="Y"
VALX$= Y

This is a very limited and a "sometimes-maybe" proposition. DEF has the ability to also handle numeric functions. This ability, as well as using parameters in argument evaluation, is beyond VAL's means.

When attempting a program conversion you may run across a few Sinclair BASIC terms that are completely unfamiliar to you. The terms USR, PEEK, and POKE are not procedures for the examination of some strange alien creature. They are primarily associated with direct access to memory. To call a machine language routine that begins with a specific address, USR is used. This will start a machine language program running. POKE is used by the T/S-1000 to store a numeric value at a specific address in the computer's memory. For example:

POKE 17529, 38

POKEs the value 38 into address 17529. Conversely, the PEEK command is used to read certain addresses to see what is stored there. The PEEK command is followed by the address to be PEEKed.

PRINT PEEK 17529

would PRINT the number 38. When you are translating a program from Sinclair BASIC which contains USR, PEEK, and POKE statements, you must find out what they accomplish and then interpret that into TI BASIC.

PRINTing on the screen is accomplished by a blending of line and row markers. Memory conservation techniques notwithstanding, PRINT can be used to move the PRINT line. For example:

PRINT
PRINT
PRINT "COMPUTE"

Sinclair BASIC also allows the movement of PRINT with AT and TAB.

PRINT AT x,y

and

PRINT TAB y

TAB moves the PRINT position a prescribed number of spaces to the right. Even though TAB is present in TI BASIC, the vocabulary is different. Line changes are accomplished with colons (:). Duplicating the above examples,

PRINT::…(x) TAB (y)

and

PRINT TAB (y)

X is the number of colons necessary to equal the value of the line number (x) in the Sinclair BASIC example.

The Timex/Sinclair lacks color and sound features, but these features are of importance on the TI-99/4. TI BASIC'S color and sound statements are subprograms that begin with CALL. Clever usage of Sinclair BASIC'S character set can duplicate some of these color combinations. As a rule, however, TI BASIC CALL subprograms should be removed and not directly substituted in a program conversion to Sinclair BASIC. This allows concentration on the program's more important graphics. Consultation with Texas Instruments' User's Reference Guide will provide the proper protocol for development and inclusion of color and sound subprograms in a Sinclair BASIC converted to TI BASIC program.

To illustrate the principles of program conversion, examine these sample programs. While each program is unique in its results, the approach is similar and convertible. The purpose of this program is to display the entire character set along with the character codes.

T/S-1OOO Version

10 FORA=0 TO 255
20 LET A$ = CHR$ A
30 PRINT AT 10,13; A
40 PRINT AT 7,10; A$;"{6 SPACES}"
50 PRINT AT 7,17; A$;"{6 SPACES}"
60 PRINT AT 13,17; A$ ;"{6 SPACES}"
60 PRINT AT 13,17; A$ ;"{6 SPACES}"
80 NEXT A

TI-99/4 Version

100 FOR A=32 TO 127
110 B$=CHR$(A)
120 CALL CLEAR
130 CALL SCREEN(2)
140 PRINT TAB(13);B$;TAB(18);B$
150 PRINT
160 PRINT TAB (14) ;A
170 PRINT
180 PRINT TAB(13) ;B$;TAB( 18) ; B$
190 PRINT ::::::::
200 FOR S=3 TO 16
210 CALL SCREEN\S)
220 CALL SOUND(400,110+80*(S-3),1)
230 NEXT S
240 NEXT A

In line 10 of the Timex/Sinclair example, a loop establishes the number of character codes to be examined (the entire character set is 0 to 255). Note that the characters with codes 67-127 cannot be printed and will show on the screen as question marks. Lines 20 and 30 PRINT the code or numeric value for each character. The arrangement of the printed characters is defined in lines 30-40. In this way, you can easily interpret the delay, and read the code value and the character almost simultaneously. This program will RUN until BREAK is pressed.

Table 1:

Reference Chart Of BASIC Equivalencies

Sinclair BASIC = TI BASIC
ABS ABS
ATN ATN
CHR$ CHR$
CODE ASC
COS COS
DIM DIM
EXP EXP
FOR FOR
GOSUB GOSUB or GO SUB
GOTO GOTO or GOTO
IF IF
INPUT INPUT
INT INT
LEN LLN
LET LET
LN LOG
LOAD OLD
NEW NEW
NEXT NEXT
PRINT PRINT
RAND RANDOMIZE
REM REM
RETURN RETURN
RND RND
RUN RUN
SAVE SAVE
SGN SGN
SIN SIN
SQR SQR
STEP STEP
STOP STOP
STR$ STR$
TAB TAB
TAN TAN
THEN THEN
TO TO
VAL VAL
CLS CALL CLEAR

Table 2:

Substitution Chart For BASIC Nonequivalents

Sinclair BASIL =TI BASIC
NFW BYE
PRINT DISPLAY
GOTO (W AND X=1)+(Y AND X=2)+(Z AND X=3) ON X GOTO W,Y,Z
IF X THFN GOTO Y IF X THEN (Y)
LET X=Y+Z LET X=Y+Z or X=Y+Z
PAUSE or FOR= X=Z TO Y NEXT X FOR X=Z TO Y NEXT X
INKEY$ CALL KEY
A$Q(X TOZ) SEG$(A$,X,Y)
PI 4*ATN(1)
LET X$="Y" VAL X$=Y DEF X=Y
STOP END or STOP
PRINT AT X,Y PRINT::…(X) TAB(Y)
PRINT TAB Y PRINT TAB (Y)
ASN 1 π/2 or 4*ATN(l)/2 or 2*ATN(1)
IF X=Y THEN GOTO A GOTO Z IF X=Y THEN A ELSE Z