POS

From C64-Wiki
Jump to: navigation, search
BASIC keyword
Keyword: POS
Abbreviation:
Type: Function
Token code: 185/$B9
Handling routine
in BASIC ROM:
45982–45989
$B39E–B3A5
List of all BASIC keywords


Remark: This article describes the BASIC-Command POS in BASIC V2 at the Commodore 64.

Typ: Integer Function 
General Programming-Syntax: POS(<dummy argument>)

The function POS determined the actual position of the cursor between 0 (first, leftmost column) and 79 (last, rightmost column in the second line) of the logical line on screen. The dummy argument is mandatory, but it does not have any effect on the result. Usually POS(0) will be used. The fastest possible execution time provides the form POS(π).

If the dummy argument is missing the BASIC error ?SYNTAX ERROR will occur.

Some strangeness of the BASIC interpreter is revealed if a program (in direct mode too) calls the function with a distinct kind of string-type expression (see Examples). This behavior can be provoked with a constant string as an argument for POS() used multiple times. On the third call an internal structure (string descriptor stack, keeping temporarily created strings) gets filled, because of missing housekeeping for the argument strings. This leads to the error ?FORMULA TOO COMPLEX ERROR. In contrast, the FRE() function also uses a dummy argument, but does a proper cleanup not leading to this effect.

Examples[edit]

At first, place the writing position to column 30 (the 31st), then query the position and print the value:

PRINT TAB(30);POS(0)
                               30

Since POS() demands a single argument, which is not used, it could be selected in that way the interpreter takes as less time as possible to evaluate it - just in case the function is part of an iteration:

100 DIM X
110 T=TI
120 FOR I=1 TO 1000
130 X=POS(π)
140 NEXT
150 PRINT (TI-T)/60;"SECONDS"

The expression for the argument of POS() evaluates fastest with with the special constant π (Pi), followed by a . (a degenerated number which translates to a float in the fastest possible way). Even a variable (declared very early) cannot reach the previous mentioned in speed. Compared to them a "0" is the slowest variant.


Anomaly of the interpreter with a constant string as dummy argument:

PRINT POS("")POS("")POS("")

terminates with the error ?FORMULA TOO COMPLEX ERROR. The number of POS() calls needed may vary for different CBM BASIC versions, which might use other limits on internal structures.


BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π  |POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT