[Coco] DEF USR and strings?

Allen Huffman alsplace at pobox.com
Wed Oct 29 17:26:01 EDT 2025


> On Oct 29, 2025, at 4:03 PM, William Astle via Coco <coco at maltedmedia.com> wrote:
> 
> On 2025-10-29 14:48, Allen Huffman via Coco wrote:
>> I could have swore I saw someone post (maybe on Facebook) that they realized the DEF USR could accept a string parameter. I had only known to use it like this:
>> A$=“STRING”
>> X=USR0(VARPTR(A$))
> <snip>
>> It looks like BEQ L8943 is where it goes if numeric, else it continues and gets the length and address of the string variable and continues.
>> What is the syntax to make this work?
> 
> First, you leave out VARPTR completely. It's not needed if you rely on USR to pass through a string parameter. (Under plain Color Basic, you can't pass a string in but Extended Basic lets you).
> 
> The biggest problem is that if you pass a string to USRn(), VALTYP will still be flagged as string when your USR routine returns and that will trigger a TM error on the assignment (to X in your example). Your handler routine will have to actually return a value instead of doing nothing with a simple RTS. Note that if you do things right, your USRn() handler can actually return a string but the how of that is beyond the scope of this email.
> 
> If you get a TM error *with* the VARPTR in there, then you have something else wrong.

Ah, I have something else wrong. I “ldd #42” then “jmp GIVABF” to return, and see my return value is indeed 42, but the ?TM ERROR remains.

A$=“1234”
X=USR0(A$)

X=USR0(“1234”)

I am running in CoCo 3 mode. I just switched to a CoCo 2 and get the same thing.

My test code is now this:

    org $7f00

start
    jsr INTCNV          * get passed in value in D
    std 1024            * for debugging
    ldd #42
    jmp GIVABF

I do a CLEAR 200,&H7F00 before running the loader.

		— A



More information about the Coco mailing list