[Coco] DEF USR and strings?

Allen Huffman alsplace at pobox.com
Sat Nov 1 14:05:14 EDT 2025


Okay, a bit trickier, but I think I figured it out:

> On Oct 31, 2025, at 4:43 PM, Sean Conner via Coco <coco at maltedmedia.com> wrote:
> 
>  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.

For debugging, I had my code take X and store it in the first two bytes of the 32 column screen. Then I would load what was in the $9D (EXEC address) and store it next to that.

From looking at the pattern:

EXEC &HABCD

…$ABCD is in X, and in $9D (EXECJP)

EXEC (by itself)

…$ABAB is in X, and $ABCD is in $9D.

Else, called by USR.

How’s this?

;* lwasm whocalled.asm -fbasic -owhocalled.bas --map
;* decb copy -2 whocalled.bin drive0.dsk,WHOCALLD.BIN

ORGADDR equ     $3e00   ;* Where program loads in memory.

;* Absolute addresses of items in RAM variables.
EXECJP      equ     $9d     location of jump address for EXEC
VIDRAM      equ     $400    VIDEO DISPLAY AREA

;* Absolute addresses of ROM calls.
CHROUT      equ	    $A002

    org     ORGADDR

;* This code expects to have been called by USRx(x).
start       cmpx	#start      ;* called by "EXEC xxxx"?
            beq     fromexec    ;* if yes, goto fromexec
            cmpx    #$abab      ;* called by "EXEC"?
            bne     fromusr     ;* if no, must be USR. goto fromusr
            ldx     EXECJP      ;* get EXEC address
            cmpx	#start      ;* called by "EXEC xxxx"?
            beq     fromexec    ;* if yes, goto from exec
fromusr
            leax    usrmsg,pcr
            lbsr    print
            rts
fromexec    leax    execmsg,pcr
            lbsr    print
            rts

;* PRINT subroutine. Prints the 0-terminated string pointed to by X plus CR.
print       lda     ,x+
            beq     printdone
            jsr     [CHROUT]
            bra     print
printdone   lda     #13
            jsr     [CHROUT]
            rts

usrmsg      fcc     "FROM USR"
            fcb     0

execmsg     fcc     "FROM EXEC"
            fcb     0

            end





More information about the Coco mailing list