Re: DEF USR and strings?

Allen Huffman via Coco <coco-uNHYcr1XS/wmlAP/[email protected]>
Newsgroups gmane.comp.hardware.tandy.coco
Message-ID <[email protected]>
Okay, here is an update. From looking at the Unravelled book, when USR jumps to the code, it sets up a few things.

Register A will be VALTYP. 0 is a number, 255 is a string.

If string, X will point to the string descriptor.

Knowing that, the code can then decide if it looks at X to parse the string, or if it calls INTCNV to parse the number and load that into the D register.

Here is a simple proof-of-concept that shows the type:

* lwasm defusr.asm -fbasic -odefusr.bas --map

* Test of DEF USR.

ORGADDR equ     $3f00

VIDRAM  equ     $400    VIDEO DISPLAY AREA
INTCNV  EQU     $B3ED   * 46061
GIVABF  EQU     $B4F4   * 46324

    org ORGADDR

start
    cmpa #0             * 0=number
    beq shownumber
    cmpa #255           * 255=string
    beq showstring

    ldx #msgunknown
    bsr print

    ldd #-1             * Return -1 as an error code
return
    jmp GIVABF

shownumber
    ldx #msgnumeric
    bsr print
    ldd #0
    bra return

showstring
    ldx #msgstring
    bsr print
    ldd #0
    bra return

* PRINT subroutine. Prints the string pointed to by X.
print
    lda ,x+
    beq printdone
    jsr [$a002]
    bra print
printdone
    lda #13
    jsr [$a002]
    rts

* Data storage for the string messages.
msgstring
    fcc "STRING"
    fcb 0

msgnumeric
    fcc "NUMBER"
    fcb 0

msgunknown
    fcc "UNKNOWN"
    fcb 0

    end
    

When I load this and set it up using

DEF USR0=&H3F00

I can then see it print things based on the data type I pass in:

A=USR0(0)
NUMBER

A=USR0(“HELLO”)
STRING

This should allow one to receive either a number or a string and handle both.

Looks like a new blog post is coming…

		— Allen

-- 
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.