Mar 96 Tips
Volume Number: 12
Issue Number: 3
Column Tag: Tips & Tidbits
Tips & Tidbits
By Steve Sisak, Contributing Editor
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
Calling PowerPC Code
From 68K Code
There is a lot of information out there about calling 68K code from PowerPC
code, but there is very little about calling PowerPC code from 68K code.
Here is a nice method for calling PowerPC code from 68K code. I am using
CodeWarrior 7. This is a bit lengthy so hang in there:
There are three steps required to get things up and running. Let’s look at a
sample scenario:
You have a 68K application that you just can’t convert to PowerPC code (I don’t
know why you can’t convert it, but just bear with me), but you can take some of the
time-critical code and convert it to a PowerPC shared library and call it from the 68K
code.
Suppose you have two functions that perform data compression:
long CompressData( unsigned char *inBuffer,
unsigned char *outBuffer,
unsigned long inBufferSize );

long UncompressData( unsigned char *inBuffer,
unsigned char *outBuffer,
unsigned long inBufferSize );
Step 1 - Create a PPC shared library containing your functions.
We are going to export these functions using the #pragma export directive. This
is set in the PPC Prefs area of Codewarrior preferences.
“the shared library”
// Prototypes
#pragma export on
#ifdef __cplusplus
extern "C" {
#endif
long CompressData( unsigned char *inBuffer,
unsigned char *outBuffer,
unsigned long inBufferSize );

long UncompressData( unsigned char *inBuffer,
unsigned char *outBuffer,
unsigned long inBufferSize );