[Coco] DEF USR and strings?
Sean Conner
sean at conman.org
Fri Oct 31 17:43:38 EDT 2025
It was thus said that the Great Allen Huffman via Coco once stated:
> Is there a way to tell if a routine was called from USR versus EXEC?
Maybe.
Address $9D contains the address EXEC uses to jump to your code, so that
should be called address. Also, X will also be this address (implementation
detail).
For Color BASIC, you need to know you are running under Color BASIC.
Address $112 is the address for USR, so this should point to your code.
Also, upon calling, X should be equal to $AA2F and B should be 6 (both are
implementation details).
For Extended Color BASIC, you need to know you are running under Extended
Color BASIC (16 bits at $8000 are $4558). Addresses $013E through $0150
contain the USRn addresses, so one of these 10 addresses should point to
your code. Also, A will equal the contents of address $06. If A=0, then
X=$4F; if A=255, then X is pointing elsewhere (the string descriptor).
For Disk Extended Color BASIC, you need to know you are running under Disk
Extended BASIC (16 bits at $C000 are $444B). The USRn addresses are now
$095F through $0971, but other than that, it's the same as Extended Color
BASIC.
Based on all that, I think the best method might be (completely untested):
mycode cmpx #mycode
beq called_by_exec
; otherwise, assume called by USR/USRn
Good luck.
-spc
More information about the Coco
mailing list