[Coco] What? No MOD?!
William Astle
lost at l-w.ca
Sun Dec 29 23:27:10 EST 2013
On 13-12-29 09:03 PM, Rogelio Perea wrote:
> This typed from memory (late 40s and is starting to haze). Program will
> probably run as is on a TRSDOS Model III and IV - not on cassette based
> BASIC... and as noted by Chris Osborn, the CoCo ECB won't handle more than
> one variable on the DEF FN statement *despite* the ECB manual calling for
> 'variables' on the review of it, plural but not quite - the simple DEF FN
> examples on that book only show a one variable defined function. Better off
> writing the thing as a subroutine in ECB.
You might be able to do it with a USR function in ECB with some clever
programming in assembly. That might be a bit of a pain in the rear,
though. With sufficient cleverness, it could also be accomplished with
plain color basic. (If you do a bit of extra parsing, you can actually
get multiple parameters into USR. It looks something like USR(X),Y but
it does work, and has the added benefit of generating a syntax error if
the USR function is not installed.)
I took a look at the DEFFN code in the ROM and found that it would be
quite difficult to extend it to multiple variables due to the way the
book keeping is done. (There's only 4 bytes for state in the record that
is put on the stack but you'd need more than that for multiple
variables.) I suspect multiple variables were part of the original plan
but were nixed due to ROM space.
To be fair, though, this is the first time I've ever encountered a
situation where I would be tempted to use DEFFN.
Depending how often you need to do a modulus, you might consider just
writing (X-INT(X/Y)*Y) each time you need it.
More information about the Coco
mailing list