FB II Compiler
FB II COMPILER
Call code resource in a pointer
How do I go about loading let's say a DCOD into a pointer and calling it?
is it as simple as:
DEF FN codeinnapointer(a,b,c) as theptr&
Don't do it that way, because an FB "FN" manipulates the stack pointer in a different manner than your DCOD code requires. Instead, just use the CALL <address> statement:
CALL theptr& (%a, %b, %c)
Note the following:
1. You can only pass 2-byte (short) integers and 4-byte (long) integers. If your DCOD code expects a short integer parameter, you _must_ precede the argument with "%" when you call the routine (as shown above). If you don't use the "%" prefix, CALL tries to pass the parameter as 4 bytes.
2. This version of CALL cannot be used to call a routine that returns a value. This is one disadvantage of using this syntax compared to using the CALL <DCODresName$>... syntax. (However, I undestand from your last post why you prefer not to use the latter syntax.)
Here's how I call code resources in a pointer...
LOCAL FN CallMyCode(codePtr&, param1&, param2&)
` CLR.W -(A7) ; make room for the return word
` MOVE.L ^param1&,-(A7)
` MOVE.L ^param2&,-(A7)
` MOVEA.L ^codePtr&, A0
` JSR (A0)
` MOVE.W (A7)+,^err%
ENF FN =3D err%