[Coco] Returning a string to basic ?
Bob Devries
devries.bob at gmail.com
Tue Sep 20 18:16:38 EDT 2011
Rogelio wrote:
> 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 ;-)
Don't forget to terminate the string with a $FF byte, and put the length of
the string back into the first byte.
Regards, Bob Devries
Dalby, QLD, Australia
----- Original Message -----
From: "Rogelio Perea" <os9dude at gmail.com>
To: "CoCoList for Color Computer Enthusiasts" <coco at maltedmedia.com>
Sent: Wednesday, September 21, 2011 8:11 AM
Subject: Re: [Coco] Returning a string to basic ?
> 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
>>
>
> Elaborating:
>
> 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
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
More information about the Coco
mailing list