Re: DEF USR and strings?

William Astle via Coco <coco-uNHYcr1XS/wmlAP/[email protected]>
Newsgroups gmane.comp.hardware.tandy.coco
Message-ID <[email protected]>
On 2025-10-29 16:04, Allen Huffman via Coco wrote:
> Cool. The Extended Color BASIC manual even showed how to return a string:
> 
> A$=(USR1(VARPTR(A$))
> 
> You can have your ML subroutine modify B$'s value and then end the routine with an RT$ instruction. This causes U$R to return with B$’s modified value.
> 
> Weird use of extra parens, though.
> 
> 		— A
> 
The extra parens are definitely not needed. And A$=(USR1(VARPTR(A$)) 
will absolutely not work for returning a string if it just falls off the 
end with RTS. That *will* give a TM error.

You need to know exactly how the Basic ROM handles strings to be able to 
do this correctly. That's a bit more complicated than it sounds. You 
have to properly handle your string return value by making sure it 
*doesn't* point to any other string data in string space and make sure 
you put it on the string stack appropriately. If you don't get that 
right, you can have things go excitingly wrong during garbage 
collection. You also should not modify strings in place *at all* because 
the string data might be pointing to the Basic program text.

That might actually be a good topic for exploration on your blog.


-- 
Coco mailing list
[email protected]
https://pairlist5.pair.net/mailman/listinfo/coco
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.