usage of def fn in basic

Post Reply
Crayon21
Posts: 346
Joined: Sun Nov 04, 2018 2:33 am

usage of def fn in basic

Post by Crayon21 »

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
:twisted:
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: usage of def fn in basic

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

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

Re: usage of def fn in basic

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

Re: usage of def fn in basic

Post 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
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
:twisted:
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: usage of def fn in basic

Post 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
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply