[Coco] DEF USR and strings?

William Astle lost at l-w.ca
Wed Oct 29 18:12:44 EDT 2025


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.



More information about the Coco mailing list