TS2068 Programming Tips

Publication

Pub Details

Date

Pages

See all articles from SYNC v4 n2

Although the TS2068 users manual does an outstanding job in acquainting the user with the computer, obviously it cannot include everything. Articles in SYNC will help you increase your ability to use this new machine. Let’s begin by looking at a few tips and techniques to add to your repertoire.

Variable Names

When it comes to variable names, the computer sees no difference between upper and lower case letters, so

LET a=5: PRINT A

will cause the computer to print a 5.

This holds true even for longer variable names, so SCORE, score, Score, and SCorE are all the same to the computer—not as strings, but as variable names.

Attribute Assignment

Four main attributes can be assigned to a character: PAPER and INK colors, and FLASH and BRIGHTness. In addition, OVER and INVERSE can be assigned to any character. PAPER and INK commands are used with color numbers, while the other attributes are used with a 1 to turn them on or a O to turn them off.

When an attribute is assigned as a separate command, e.g.,

INK 2: PRINT "Hello"

it will remain in effect—it becomes the permanent attribute—until another command is issued to change it. The manual points out that you can use the syntax.

PRINT INK 2; "Hello"

so that the INK command will affect only that print statement and not change the permanent color in the computer’s memory.

Actually, you can combine any of the attribute statements with any of the print or graphic commands.

Some of the possible combinations are:

PRINT FLASH 1; "Flash"
DRAW INK 5;50,50
CIRCLE BRIGHT 1;127,87,50
PLOT PAPER 4;60,80

Remember that an attribute is assigned to a whole character cell—the block of 8 by 8 pixels that a letter occupies. So, there is a vast difference between:

CIRCLE 127,87,50 and
CIRCLE FLASH 1;127,87,59

The latter will draw a circle with the usual thin line, but the flash command will affect all the character blocks that the line passes through.

You can use this situation to your advantage in many cases. The following program, for instance, will plot a line the thickness of a character cell, which 1s more effective for a bar graph than a thin line:

10 PAPER 1:CLS: INK 5 
15 FOR y=1 TO 30
20 PLOT PAPER 5;10,y
25 NEXT y

INPUT LINE

The INPUT LINE variation of INPUT suppresses the quotation marks of the input prompt. If you use

INPUT LINE a$ 

only the L cursor will show at the bottom of the screen.

This function has the advantage of preventing the use of STOP at this point of the program. Normally, you can delete the left quotation mark when the computer is waiting for an input and enter STOP; with the quotation marks missing, the STOP will be interpreted as a string rather than as a command. (For some reason, however, pressing shifted 6 while the computer is waiting for the input will stop the program.)

When you want to use INPUT LINE with a string, the proper syntax is:

INPUT "What is your name";LINE a$

SCREEN$

SCREEN$ is used to save and load screen displays, but it can also be used to check what is appearing in any position on the screen.

PRINT SCREEN$(10,15)

will return the character printed in the center of the screen.

The SCREEN$ function is most useful in an IF-THEN construction:

IF SCREEN$(5,4)="A" THEN ...

SCREEN$ has a few limitations: an inverse character will be read as its true video counterpart, and graphic symbols — from the graphic set or user-defined — will not register at all.

OVER

The OVER command does not simply print one character over the other, or the following commands:

10 PRINT "█"
15 OVER 1
20 PRINT AT 0,0;"!"

would result in a black square in the corner of the screen.

Actually, what you get is a white exclamation point on a black square.

When OVER is in effect and two characters are being PRINTed at the same spot, the following rules apply:

  • Where both characters are PAPER color, the combined character remains PAPER color.
  • Where only one of the characters is INK color, the combined character is PAPER color.

Try:

10 CIRCLE OVER 1;127,87,50
20 GO TO 10

This program repeatedly draws a circle in the same spot, but, since OVER is in effect, the circle is erased on every other loop.

You can use PLOT OVER 1 in the same way to erase a plotted line.

DEF FN, FN

With DEF FN and an appropriate variable (a single-letter numeric or string variable, you can define your own mathematic and string functions, calling them up later with FN. (Both DEF FN and FN are accessed by shifting into the extended mode, holding down symbol shift, and pressing 3 or 4.)

If, for instance, you should want to raise a number to the power of five and find the square root of the result, you would use:

PRINT SQR(x^5)

If you want to do that same operation on different numbers, you can define a *square root of the fifth power” function:

DEF FN a(x)=SQR(x^5)

The variable “a” is the function variable. The parenthetical “x” stands for the number that the function will be performed on. The function is defined by using the parenthetical variable in the mathematical expression.

Now, if you want to apply the function to the number 23, you would use:

PRINT FN a(23)

You can define a function in terms of more than one variable. For instance, if you want to average three numbers, you can define an averaging function like this:

DEF FN a(x,y,z)=(x+y+z)/3

Use this function in this way:

PRINT FN a(12,17,43)

You can also define string functions. If you want (for some strange reason) to form a new string out of the first and last letters of an old string, you can define that function as:

DEF FN a$(z$)=z$(1)+z$(LEN z$)

In this case, a$ 1s the function name, and z$ stands for the string that will be operated on. The slicing operation that is defined takes the first letter of z$ and connects it to the last letter.

10 DEF FN a$(z$)=z$(1)+z$(LEN z$)
15 LET b$="HELLO"
20 LET c$=FN a$(b$)
25 PRINT c$

ON ERR

There are three forms of the ON ERR (on error) command: ON ERR GOTO/GOSUB, ON ERR CONT, and ON ERR RESET.

The ON ERR GO TO and ON ERR GO SUB commands prevent the usual stopping of the program with an error report. The ON ERR statement is placed at or near the beginning of the program—any spot, really, as long as it is before the spot where the error might occur.

One of the great advantages of the ON ERR statement is that it can prevent someone from BREAKing into your program, because BREAK is considered by the computer to be an error.

This program draws and erases a circle on the screen repeatedly; you will not be able to use BREAK.

10 ON ERR GO TO 15
15 CIRCLE OVER 1;127,87,50
20 GO TO 15

Since line 10 instructs the computer to go to 15 when an error is encountered, you will have to shut off the computer to regain control.

You might have a five-item menu on the screen for the user to choose from:

10 ON ERR GO TO 20
20 IF INKEY$="" THEN GO TO 20
30 IF VAL INKEY$<1 OR VAL INKEY$>5 THEN GO TO 20

Line 30 prevents the computer from accepting any number other than those from 1 to 5; line 10 prevents the user from BREAKing into the program. Unfortunately, line 10 will also prevent you from breaking into the program to make any improvements. So, you can add:

25 IF INKEY$="Z" THEN GO TO 100

The chance that someone would enter a capital Z when presented with numerical menu choices are minimal, but you can use it to get to a subroutine that will allow you to STOP the program.

100 ON ERR RESET: STOP

The RESET command enables the usual errors to be detected and acted upon once again, so the STOP command will be executed. (STOP, like BREAK, is considered an error.)

You can use ON ERR GO TO and ON ERR GO SUB in similar situations, as well as in debugging your programs.

ON ERR CONTINUE causes the program to resume from the line at which the error occurred.

5 ON ERR GO TO 25
10 LET a=0
15 PRINT INK a;"hello"
20 LET a=a+1: GO TO 15
25 LET a=0: ON ERR CONTINUE

In this program, an error occurs when the ink color is higher than 9 (8 is for transparent, 9 is for contrast.) The error sends the program to line 25, where the variable is reset to zero and the command is given to continue from the point where the error occurred.

A Demonstration

“Random Draw” is a program that uses some of the tips presented in this article. Once you RUN it, you will not be able to stop it, so you might want to save it before RUNning.

The program will draw randomly colored lines of random lengths on a black background. The first line starts at the center of the screen, going off in a random direction; each subsequent line begins where the last ended. ON ERR is used to send the program back to the center of the screen if a line has gone off an edge. Let the program run a while and you will notice that instead of pixelthin lines being drawn, blocks begin to fill the screen and change color. This is an example of how attribute assignment affects an entire character cell, and not just the pixels you are drawing or plotting. As a new line passes through a character cell, all the other lines in that cell are changed to the current color.

1 REM random draw
5 PAPER 0: CLS: BORDER 0
10 DEF FN r(x)=INT (RND*x)
15 ON ERR GO TO 20
20 PLOT 127,87
25 LET a=FN r(150)-75
30 LET b=FN r(150)-75
35 LET i=FN r(7)+1
40 DRAW INK i;a,b
45 GO TO 25

Line Notes

5: Sets the entire background to black.

10: Defines a “random” function so that the random number will be one of x different integers (beginning at a default of 0).

15: When an error occurs—when a line is going to be drawn off-screen—the program is sent back to line 20, which lets the drawing start at the center of the screen again.

25,30: Define a and b as random numbers between -75 and +75 (150 different numbers, beginning at -75)

35: Defines i as a random number between 1 and 7.

Products

 

Downloadable Media

 

Image Gallery

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top