Page 1 of 1

usage of def fn in basic

Posted: Tue Nov 26, 2019 12:25 am
by Crayon21
can it be used for graphics?

Re: usage of def fn in basic

Posted: Tue Nov 26, 2019 9:49 am
by XavSnap
Hi Crayon21,
Yes, but only with a numérique defined value…

10 DEF FN X=INT(a/2)
20 DEF FN Y=INT(b/2)

10 LET x=0: LET y=0: LET a=10
20 DEF FN p(x,y)=a+x
30 DEF FN q()=a+x*y
40 PRINT FN p(2,3),FN q()
RTFM > http://www.worldofspectrum.org/ZXBasicM ... chap9.html

Re: usage of def fn in basic

Posted: Wed Jan 08, 2020 4:06 pm
by Shaun_B
Crayon21 wrote: Tue Nov 26, 2019 12:25 am can it be used for graphics?
In what way? DEF FN can be used for any calculations, so yes. You may also be able to use the USR command with it as well to call let's say certain ROM or MC routines directly.

Regards,

Shaun.

Re: usage of def fn in basic

Posted: Thu Jun 24, 2021 8:59 pm
by stefano
there is even an interesting trick to even use DEF FN recursively, IIRC using VAL cleverly to enable the recursion only up to desired result.

Re: usage of def fn in basic

Posted: Sat Jul 09, 2022 2:58 am
by Crayon21
Shaun_B wrote: Wed Jan 08, 2020 4:06 pm
Crayon21 wrote: Tue Nov 26, 2019 12:25 am can it be used for graphics?
In what way? DEF FN can be used for any calculations, so yes. You may also be able to use the USR command with it as well to call let's say certain ROM or MC routines directly.

Regards,

Shaun.
example please

Re: usage of def fn in basic

Posted: Sat Jul 09, 2022 8:58 pm
by 1024MAK
The more complex uses of DEF FN (such as using DEF FN recursively, or using it in calling machine code) can get confusing rather quickly.

I suggest you get used to using it for less complex uses first.

Back to your original question, you could work out the calculation needed for working out the relationship between the BASIC graphical position (as used with PLOT) and the actual address of the relevant memory byte used. Then use DEF FN so that the calculation is only needed once in your program listing.

Or use DEF FN to calculate the relationship between PLOT coordinates and the PRINT AT position.

Mark