[Coco] Returning a string to basic ?
tim at franklinlabs.com
Tue Sep 20 19:16:55 EDT 2011
Wasn't this the method we used to use for string packing? My memory isn't as good as it used to be.
From: Arthur Flexser [mailto:flexser at fiu.edu]
Sent: Tuesday, September 20, 2011 05:33 PM
To: 'CoCoList for Color Computer Enthusiasts'
Subject: Re: [Coco] Returning a string to basic ?
Strings under Basic need not be terminated by anything; the lengthbyte tells Basic where the end is.ArtOn Tue, Sep 20, 2011 at 6:16 PM, Bob Devries wrote:> 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" > To: "CoCoList for Color Computer Enthusiasts" > 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 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>>> --> Coco mailing list> Coco at maltedmedia.com> http://five.pairlist.net/mailman/listinfo/coco>--Coco mailing listCoco at maltedmedia.comhttp://five.pairlist.net/mailman/listinfo/coco
More information about the Coco