I figured it 'all' out :-)

the Tech-docs say DE holds a pointer to a string descriptor
this is true for the argument that is passed as arg.

However, for returning a string you do not only have to set DE to the
new string descriptor, but also the 2byte location 0F7F8h (DAC). And i'm
not even sure if DE is being used, but just to be safe.... :-)

Changing the original descriptor i have not tried but i imagine it can
do damage (leaks?).

This i already tried before but... i did an increase to many..
the routine was supposed to convert strings like "A" to "rA"...
"rA" + 1 = "A".. DOH! :-)

anyway, an example
------------------

descriptor: db 0,0,0

basic_callable_function:

        cp      A,3
        ret     nz              ;; not a string as arg

        ;; do stuff, maybe even change the 'descriptor' for returning
        ;; some other string besides a "" string

        LD      DE,descriptor
        LD      [0F7F8h],DE
        LD      A,3
        ret

This will return a string with length 0. Upon return the string is
copied! into the return string, which has it's own descriptor.

Maybe a nice thing for the FAQ?

 Floris

[EMAIL PROTECTED] wrote:
> 
> Maarten ter Huurne wrote:
> 
> > As far as I know, 'usr' can use a string argument,
> > but will always return an integer.
> 
> Incorrect - see below...
> 
> Floris wrote:
> 
> > no,
> >
> > a usrdef can return a string. In fact, when you give a string as
> > argument, you get type-errors if you return a non-string (well on my
> > 8235 anyway).
> 
> True. IIRC, at entry of the USR routine, register A holds
> the type of the argument and the system variable DAC holds the actual
> value or the string descriptor.  At the exit of the USR routine,
> DAC has to contain the return value (or string descriptor) and
> register A the return type.  This is actually very fancy: you can
> use *one* USR routine which can return different results and result
> types depending on the value and/or type of the argument.
> 
>      Eric
>

****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED]
and put "unsubscribe msx [EMAIL PROTECTED]" (without the quotes) in
the body (not the subject) of the message.
Problems? contact [EMAIL PROTECTED]
More information on MSX can be found in the following places:
 The MSX faq: http://www.faq.msxnet.org/
 The MSX newsgroup: comp.sys.msx
 The MSX IRC channel: #MSX on Undernet
****

Reply via email to