How to get the address of a basic string and use this address from ML to tranfer data between Basic and ML:
From Basic: SYS R,A$ Your ML code at address "R": jsr $CEFD ;CHKCOM jsr $CD9E ;FRMEVL jsr $D6A3 ;GETSTR - Pointer to string in $22/$23 (pha ;StrLen in A)Another way to do similar things is posted by Anders Carlsson here.
A good thing to know is that a string either is located in the string memory area or in the program itself. For example:
0 A$="HELLO" : REM This string uses the program's memory. If you change it from ML, then the program itself will be changed.
1 A$=A$+" THERE" : REM Now the string has been modified and will after this have it's own memory.
So if you just want to transfer stuff from ML to Basic and not the other way around, then here is a third way (my own tip): You could start your program with for example 0 A$="spacespacespace". Then look at the basic start address (43/44). Add a few bytes, and then store your data there from ML and you will have it in A$ in Basic.
$C533: Rebuild Basic text link pointers (tip by Daniel Kahlin).
This would rarely be used unless you are moving a Basic program within memory.
$C659: Reset execution to start of program and perform CLR (set pointers to variables).
$C7AE: Handle next Basic statement from current position. Not really the entry point for RUN ($C871), but it works..
If you have a ML routine or something else you want to store together with your basic program, then here is a neat way of doing it.
Now to the neat thing. After this you can do any normal basic editing to the program (add, remove lines, edit, run, save etc) and the extra data will still be there and safe! It's start position will move, but that's all. So to access the data from basic, look at pos (45,46) which now is the end of the extra data, and then subtract the lengt of the data and you will get it's start pos.
The data could for example be a relocatable ML routine. To do that, just don't use any direct addresses to things inside the routine. For example, instead of JMP, use CLC followed by BCC.
The only thing I have come across that destroys the data (removes it) is Programmer's Aid's FIND command. But RENUMBER works fine!!!
I used this technique in my Vic Menu program.
On modern basic languages, you can use the LOCATE command to place the cursor somewhere on the screen. CBM Basic V2 only has TAB() and SPC() that can move the cursor sideways. But how do you put the cursor on a specific row? This is how:
That's it. The extra print is needed for the trick to work, so you use it for example