Futurebasic/Language/Reference/universalfn

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Syntax[edit | edit source]

UNIVERSALFN

Description[edit | edit source]

This function executes the routine located at the memory address specified by procPtr&, optionally passing it the parameters specified in parm1, parm2 etc., and optionally returns a result. The flags parameter contains information about how parameters should be interpreted when they're passed to the routine, and what type of value (if any) should be returned. Unlike the CALL statement, the UNIVERSALFN function can be used to make "mixed mode" calls; that is, UNIVERSALFN allows your PPC-compiled program to call 68k-compiled routines, and vice-versa. (Note: if you are making a mixed mode call, then procPtr& must be a pointer to a "routine descriptor."See Inside Macintosh: PPC System Software for more information.) In the current version of FB, UNIVERSALFN can only call "Pascal stack-based" routines; this is the style which is most often supported by the MacOS Toolbox. Before you use UNIVERSALFN, you should make sure you know how many parameters (if any) the procPtr& routine expects, what the expected data type of each parameter is, and the data type (if any) that the routine will return. Having made this determination, you should then set the flags parameter to the sum of one or more of the following constants, as appropriate (note: the flags parameter must be a static integer expression; it can't be a variable):

Constant Description

_rtnNone (0) Routine does not return a value.

_rtnByte (16) Routine returns a byte value.

_rtnWord (32) Routine returns a word (2-byte) value.

_rtnLong (48) Routine returns a long (4-byte) value.

_p1Byte (64) Routine expects 1st parameter to be a byte.

_p1Word (128) Routine expects 1st parameter to be a word.

_p1Long (192) Routine expects 1st parameter to be a long.

_p2Byte (256) Routine expects 2nd parameter to be a byte.

_p2Word (512) Routine expects 2nd parameter to be a word.

_p2Long (768) Routine expects 2nd parameter to be a long.

_p3Byte (1024) Routine expects 3rd parameter to be a byte.

_p3Word (2048) Routine expects 3rd parameter to be a word.

_p3Long (3072) Routine expects 3rd parameter to be a long.

_p4Byte (4096) Routine expects 4th parameter to be a byte.

_p4Word (8192) Routine expects 4th parameter to be a word.

_p4Long (12288) Routine expects 4th parameter to be a long.

_p5Byte (16384) Routine expects 5th parameter to be a byte.

_p5Word (32768) Routine expects 5th parameter to be a word.

_p5Long (49152) Routine expects 5th parameter to be a long.

through...

_p13Byte = (&40000000) Routine expects 13th parameter to be a byte.

_p13Word = (&80000000) Routine expects 13th parameter to be a word.

_p13Long = (&C0000000) Routine expects 13th parameter to be a long.

Routine constants are located in the TlBx Stndard.Incl. The maximum number of parameters that can be used for a universal function is 13. Example: _myProcFlags = _rtnWord + _p1Word + _p2Long x% = UNIVERSALFN(procAddr&, _myProcFlags, 307, fred&) Note: It's vital that you set up the flags parameter properly, so that the stack pointer will be adjusted correctly when the routine is called. An incorrectly adjusted stack pointer can cause your program to crash.

See Also[edit | edit source]

UNIVERSALPROC; CALL <address>