A lot of the ML routines that we can access with the SYS command actually require the Accumulator, X, Y, or flags to be set to specific values. As it turns out, the BASIC SYS command actually has a way to pre-load these values into the CPU registers, as well as a way to read these back after the routine exits.
These values are stored in $30C-30F, like this:
780/$30C: Accumulator
781/7$30D: X register
782/$30E: Y register
783/$30F: Status Register/Flags
So if you wanted to call a routine like PLOT, which moves the cursor to column Y and row X, you'd set the registers like this:
POKE 781, 10
POKE 782, 5
POKE 783, 0 : REM Clear the flags
SYS 65520
This will place the cursor on row 10, column 5.
Or, if you wanted to read the cursor position, you can set the carry flag:
POKE 783,1
SYS 65520
X = PEEK(781)
Y=PEEK(782)
And yes - the X and Y are backward. The X register stores the row and Y stores the column. It probably has something to do with certain addressing modes only being available to the X register and others only being available to the Y register...

Of course, the Commander has the LOCATE command, but if you're coding for BASIC 2 (C64, PET, etc), then this is the way to directly position the cursor.
Another one that I find useful is the "stuff the keyboard" API:

This will print the appropriate commands, then position the cursor so that two presses of the RETURN key loads and runs the next program. And since the keyboard buffer conveniently has two CRs in it, your next program will run.
Here's the output (assuming F$(C) is TREK.PRG):
