[Coco] Returning a string to basic ?

Rogelio Perea os9dude at gmail.com
Tue Sep 20 18:11:30 EDT 2011

On Tue, Sep 20, 2011 at 5:43 PM, Arthur Flexser <flexser at fiu.edu> wrote:

I'm going from hazy memory on this...
> I'm assuming the string is at a known address and has a known length.
> What you need to do is this:
> Define a dummy string in the Basic program with some statement like S$="A".
> Then use the Basic VARPTR function to find the address of Basic's

pointer to the string:  ST=VARPTR(S$).
> At the address now contained in ST is a 5-byte string specifier.  The
> first (I think) byte is the string length, and the 3rd and 4th (?)
> contain the address of the string data.
> (The other 2 bytes of the 5-byte identifier are unused.)
> Using POKEs, you can modify these 3 bytes to insert the length and
> address of the string you want Basic to know about, which will then be
> referenced by S$.
> Hope that does the trick for you!
> Art


PEEK(ST) will return the length of the string variable
PEEK(ST+2) will be the MSB of the variable first character address in memory
PEEK(ST+3) will be the LSB of the variable first character address in memory

Examining RAM locations after the MSB & LSB are calculated up to the length
of the string will reveal the variable contents.

As noted, manipulating these values once a string variable has been defined
we can put whatever we want in the string variable... as long as it is at
most 255 bytes long ;-)

-- RP

More information about the Coco mailing list