[Coco] DEFFN in Extended BASIC

Arthur Flexser flexser at fiu.edu
Sat Jan 3 21:43:23 EST 2015


DEF FN can take only a single argument, contrary to what it says in some
Tandy documentation.

Art

On Sat, Jan 3, 2015 at 8:32 PM, Allen Huffman <alsplace at pobox.com> wrote:

> James Jones replied to my “Optimizing BASIC” blog post and mentioned a few
> more things. One of them was the DEFFN function, which I recalled but don’t
> think I ever used it. It allows creating custom functions. I tried to look
> it up in the Getting Started with Extended Color Basic, but the appendix
> referred me to page 193 and it was not mentioned that. I did find it
> demonstrated in the Super Extended Color Basic manual for the CoCo 3.
>
> You can make a function called “A” that multiplies an integer by 1000:
> DEF FNA(X)=X*1000
>
> FOR A=1 to 10
> PRINT FNA(A)
> NEXT A
>
> If you use X*1000 more times in your program than the overhead of the DEF
> FN line, you save code space.
>
> It said you could pass multiple parameters, but there was no example.
> Using a command like C didn’t work, but a space did. Here is a function I
> will be using in my Pac-Man demo to convert an X and Y to a POKE location
> on the VDG text screen:
>
> DEFFNP(X Y)=1024+Y*32+X
>
> Now instead of doing:
>
> P=1024+Y*32+X:POKEP,42
>
> P=FNP(X Y):POKEP,42
>
> Or,
>
> POKE1024+Y*32+X,42
> vs
> POKEFNP(X Y),42 — four bytes less
>
> Defining the function took 25 bytes, so I would have to use this at least
> 7 times in my code before I would save any time.
>
> It does appear to be a tradeoff in speed. Doing a FOR/NEXT of X/Y to POKE
> every byte on the screen took more time.
>
> Cool.
> --
> Allen Huffman - PO Box 22031 - Clive IA 50325 - 515-999-0227 (vmail/TXT
> only)
> Sub-Etha Software - http://www.subethasoftware.com - Established 1990!
> Sent from my MacBook.
>
> P.S. Since 4/15/14, I have earned OVER $600  in Amazon gift cards via
> Swagbucks! Use my link and I get credit:
> http://swagbucks.com/refer/allenhuffman
>
>
>
>
>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list