$Y with Terminal I/O
The following table shows the effects of different characters on $Y.
Echoed Character |
ASCII Code |
Effect on $Y |
<FORM FEED> |
12 |
$Y=0 |
<RETURN> |
13 |
$Y=$Y |
<LINE FEED> |
10 |
$Y=$Y+1 |
<BACKSPACE> |
8 |
$Y=$Y |
<TAB> |
9 |
$Y=$Y |
Any printable ASCII character |
32-126 |
$Y=$Y |
The S(ecret) protocol of the OPEN and USE commands turns off echoing. It also prevents $Y from being changed during input, so it indicates the true cursor position.
A WRITE $CHAR() that changes vertical position also changes $Y. A WRITE * that changes vertical position does not change $Y. For example, WRITE $Y,$CHAR(10),$Y performs the line feed and increments $Y. In contrast, WRITE $Y,*10,$Y performs the line feed but does not increment $Y. (See the WRITE command for further details.)
Because WRITE * does not change $Y, you can send a control sequence to your terminal and $Y will still reflect the true cursor position. Since some control sequences do move the cursor, you can use the SET command to set $Y directly. For example, the following commands move the cursor to column 20 and line 10 on a VT100-type terminal and set $X and $Y accordingly:
SET dy=10,dx=20
WRITE *27,*91,dy+1,*59,dx+1,*72
SET $Y=dy,$X=dx
ANSI standard control sequences (such as escape sequences) that the device acts on but does not output can produce a discrepancy between the $X and $Y values and the true cursor position. To avoid this problem, use the WRITE * statement and specify the ASCII value of each character in the string. For example, instead of using the following code:
WRITE $CHAR(27)_"[1m"
use this equivalent form:
WRITE *27,*91,*49,*109
As a rule, after any escape sequence that explicitly moves the cursor, you should update $X and $Y to reflect the actual cursor position.