## usage of def fn in basic

Crayon21
Posts: 286
Joined: Sun Nov 04, 2018 2:33 am

### usage of def fn in basic

can it be used for graphics?
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
XavSnap
Posts: 1661
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

### Re: usage of def fn in basic

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
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

### Re: usage of def fn in basic

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.
stefano
Posts: 494
Joined: Tue Dec 11, 2012 9:24 am
Contact:

### Re: usage of def fn in basic

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.
Crayon21
Posts: 286
Joined: Sun Nov 04, 2018 2:33 am

### Re: usage of def fn in basic

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.
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
1024MAK
Posts: 4192
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

### Re: usage of def fn in basic

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