MSX BASIC – lesson 5

da | Nov 20, 2023 | MSX BASIC | 0 comments

“MSX BASIC” COLUMN by Orazio Cacciola (part 5)

The TAB, LOCATE, POS and CRSLIN functions

Today I will talk about the functions that are used to help us position our prints on the non-graphic screen and also know the cursor positions. Since they are not very complex, I will explain all four.

TAB is a function that helps us position the cursor at a point on the screen line where it is located at that moment. It is always used together with PRINT, i.e. after:
PRINT TAB(10). The argument after the function must be a number or numeric variable and cannot be omitted. If the argument exceeds the length of the line, it will
printed in the next one. This performs an increasing horizontal positioning, which means it cannot go back. To make it clearer I'll give an example
with a small program:

10 PRINT "NAME"; TAB(20); "CITY'"; TAB(30); "AGE" 20 E=50:PRINT "FRANCO"; TAB(20); "MILAN"; TAB(30); And the result will be: NAME CITY AGE FRANCO MILANO 50

Remember that numeric variables will be moved by one character. If we admit, I would have put TAB(30); “MILANO” and then TAB(20); And, since the latter could not be turned back, it would have been printed immediately after the word MILAN: MILANO 50
It can also be used for printing on paper, nothing of what I said changes
before: LPRINT TAB(10)

The LOCATE function compared to the previous one, prints anywhere on the screen without problems. LOCATE Horizontal coordinate, Vertical coordinate, cursor (on or
worn out). Where, horizontal coordinate (X) is the number of the row where you want to print, while vertical (Y) is the column number. If the cursor is set to 0 it will not be displayed
if it is greater than 0, yes. Our screen in text mode is made up of 40 horizontal characters (from 0 to 39, by default they are 37; from 0 to 36) and 24 vertical characters (0 to 23),
assuming that the function key display line is deactivated (I will explain this topic later). I open a parenthesis to say that I am only speaking
of the default screen i.e. SCREEN 0, this will also be explained later.
We want to print our sentence on line 10 of column 5, since the MSX starts from scratch, we will write:
LOCATE 9.4: PRINT “CIAO”
The MSX will not report an error if 1 of 2 or all 2 parameters of the LOCATE function exceed the screen's set values, but the results will be staggered. If the third is omitted
parameter, it will treat it as 0 (by default), so the cursor will be off.

POS(1) and LPOS(1) return the horizontal(X) coordinate of the cursor, on screen or on paper, respectively. The function argument is dummy, so it doesn't matter
its value.
X=POS(0)

CRSLIN returns the vertical (Y) coordinate of the cursor on the screen, it is not applicable on paper.
Y=CRSLIN

These last 2 functions are very useful in those text programs that use windows.
To give an example, a program that has online help and is activated by pressing a function key or any other, it is very useful to know in which position the cursor should return
after viewing the help.
And that's all, thanks and see you next time

0 Comments

Submit a Comment

Your email address will not be published. I campi obbligatori sono contrassegnati *

LEZIONE 26 – INTERVAL ON, RND ED ALTRI

LESSON 26 – INTERVAL ON, RND AND OTHERS

Good morning everyone, In this episode I will talk about an important interrupt, especially for games, when we want to make an enemy suddenly appear or a useful object, but also to create a stopwatch or a clock and many other things. The COMMAND exploits the...

LEZIONE 26 – INTERVAL ON, RND ED ALTRI

LESSON 24 – THE DATA MANAGED BY THE MSX (PART 3)

Kind regards to everyone. Today we will close this topic, I will talk about direct or random access files. But first, as I mentioned in the last episode, I will give a small explanation about the program. First of all, the first thing to say is that I used a command which...