Authors
Publication
Pub Details
Date
Pages
BASIC Terms
For this month lets check some of the other fine points of SINCLAIR BASIC not covered in the TIMEX MANUAL, and then some:
I’m certain you know that everything that an INPUT statement writes goes to the bottom part of the screen, which acts somewhat independently of the top half. In particular, its lines are numbered relative to the top line of the bottom half, even if this has moved up the actual screen display (which it does if you type lots of INPUT data).
To see how AT works in INPUT statements, try running this:
10 INPUT "This is line 1.",A$; AT 0,0;"This is line 2.",A$; AT 1,0; "This is still line 1.",A$
(just press ENTER each time it stops.) When ‘This is line 2.’ is printed, the lower part of the screen moves up to make room for it; but the position numbering moves up as well, so that the lines of text keep their same numbers.
Now try this:
10 FOR n=0 TO 19: PRINT AT n,0;n;: NEXT n
20 INPUT AT 0,0;A$; AT 1,0;A$; AT 2,0;A$; AT 3,0;A$; AT 4,0;A$; AT 5,0;A$;
As the lower part of the screen goes up and up, the upper part is undisturbed until the lower part threatens to write to the same position as the lowest PRINT line of the upper screen. The upper part starts scrolling up to avoid this.
Another refinement to the INPUT statement which can not be found in any MANUAL is; if you for instance wish to have an INPUT line which instead of INPUT "text";A$, has a string in place of the text (which could allow you to READ such text from a DATA line). You probably have found out that a line;
INPUT T$;A$
does not work. All this would accomplish, is, to let you INPUT two times, ones to T$, and ones to A$, but if you use instead:
INPUT VAL$ "T$";A$
T$ will show up as text. Try this for instance:
10 RESTORE 40: DIM A$(6,10)
20 FOR x=1 TO 6: READ T$: INPUT "Enter "; VAL$ "T$";" item ";A$(x)
30 NEXT x
40 DATA "first","second","third", "fourth","fifth","sixth"
Another way, more complex yet, would be an INPUT like this:
INPUT "This is the "' FLASH 1; VAL$ "T$"; FLASH 0;" item of the MENU'S"'VAL$ "D$";" line"; AT 3,10;"choice ";LINE A$
where D$ could be DATA READ from a second item in the DATA LINE, referring to text lines in the top screen, or anything else. The possibility of text entry in an INPUT statement is therefore unlimited, especially since the lower screen is addressed just like the upper screen. TAB, AT, INK, PAPER, FLASH and INVERSE can be used at will. Now would an IBM let you do this??
Did you know that the control characters CHR$ 22 and CHR$ 23 have effects like AT and TAB? They are rather odd as control characters, because whenever one is sent to the screen to be printed, it must be followed by two more characters that do not have there usual effect: they are treated as numbers (their codes) to specify the line and column (for AT) or the tab position (for TAB). You will almost always find it easier to use AT or TAB in the usual way rather than the control characters, but they might be useful in some circumstances. The AT control character is CHR$ 22. The first character after specifies the line number and the second the column number of course, so that
PRINT CHR$ 22+CHR$ 1+CHR$ c;
has exactly the same effect as
PRINT AT 1,c;
This is so even if CHR$ 1 or CHR$ c would normally have a different meaning (for instance if c=13); the CHR$ 22 before them overrides that.
The TAB control character is CHR$ 23 and the two characters after it are used to give a number between 0 and 65535 specifying the number you would have in a TAB item:
PRINT CHR$ 23+CHR$ a+CHR$ b;
has the same effect as
PRINT TAB a+256*b;
Lets talk some more about efficient programming! I’m sure you have heard about most of this, but let’s review anyways.
Subroutines; should be near the start of your program, since the computer searches for them from the beginning of the program area. This is also true for FOR/NEXT loops.
Define often used variables near the start of your program, the computer searches for variables also from the beginning of the variable area.
SGN PI, VAL, Variables etc. need extra time to be evaluated by the operating system, and should only be used in lines where the program doesn’t require speed.
REM lines will have to be passed when searching for a GO TO or GOSUB line and will slow down a program.
Sometimes it becomes necessary to save memory and the use of variables, VAL etc. is one option considered. Before changing all numbers to VAL strings, consider to check all your text first, to see where TOKENS could be used instead.
If a lot of conditional statements are to be checked for an occasional true occurrence, see if a line like the one below could be entered into the program flow
1050 IF condition>3 THEN IF condition<20 THEN GO TO 30
where at line 30 all the rest of the conditional statements could be checked, but only when such conditions are true. I hope you get the drift of what I mean by this, in other words think and evaluate all you enter for speed and memory usage, it may surprise you how much shorter and more efficient a program may become after applying some of the above.
Another factor to speed up program execution; use THEN IF where ever you would normally use AND. Point in case; line 155 in my FILE0 MENU LOADER, published here some time ago.
155 IF Q=50 AND J>VAL "20" THEN LET K=K-VAL "380":
If Q is not 50, one would assume that the system would quit checking the rest of the line, not so, but then you probably know what happens when one assumes, ever heard about it? “Assume makes an ASS out of U & ME, well it sure will in SINCLAIR BASIC, and it’s even worse in TIMEX BASIC, but more about it next time. Just replace AND in my MENU LOADER on line 155 in the meantime with THEN IF and notice the difference.
This should do it again for this month, and also this year, hope you had a good year, and you will have an even better 1989.