[comp.sys.mac.programmer] How do I call on assembly from C?

sjhg9320@uxa.cso.uiuc.edu (Natty Dredmon ) (06/05/91)

the generic way to use .asm from THINK C is to
lapse straight into it:

(a nonsense procedure showing how its done:)
asm
 {
 bra.w      000000
 rts
 }

If you want real examples, check out the source included in
the class libraries...

 At any rate, It's covered in a short chapter in the manual- in
 order to pass the trap the parameters its looking for
 you have to create a stack frame and load them onto it.
 If you get stuck as to how to do this, peruse Scott Knaster's
 'How to Write Macintosh Software'- it does a pretty good job
 explaining .asm to someone familiar with Higher Level Languages
 such as C or Pascal.
--
================================================================================
|                                 June 4th, 1989.                              ||                                                                              |================================================================================

pittenger-laurence@cs.yale.edu (Laurence Arthur Pittenger) (06/05/91)

Re my previous question about calling directly into assembly language:
The following command works, in Think C at any rate, as an in line
macro.  This saves the trouble of doing in-line assembly or messing
with CallPascal commands, and makes the code that much more readable:

pascal OSErr BitMapToRegion(RgnHandle region, BitMap *bMap) = 0xA8D7;

Think C accepts the assignment as a function definition.


Thanks to those who responded.
LP
-- 

Laurence A. Pittenger
CSNET  : pittenger-laurence@cs.yale.edu
BITNET : pitlaua@yalevm ,  pittenger-laurence@yalecs

wysocki@husc9.harvard.edu (Christopher Wysocki) (06/05/91)

In article <1991Jun4.190036.15349@cs.yale.edu> pittenger-laurence@cs.yale.edu
(Laurence Arthur Pittenger) writes:

>A few days back someone posted about converting Bitmaps to regions.
>There's a call at assembly location 0xA8D7 which takes (RgnHandle
>theRgn, BitMap* theMap) as parameters to do this.
>
>Well, I'm running Think C and it doesn't have this call.  But I
>figured I could just call on the command directly, since I know its
>address.  But I can't figure out how to do it.
>
>I tried CallPascal (theRgn, theMap, 0xA8D7) but was criticized by the
>debugger for an "odd address".  I also tried making a function type of
>the appropriate nature and assigning BitmapToRgn = (functype) 0xA8D7,
>but it didn't like BitmapToRgn (theRgn, theMap) either.
>
>So how do I do it?

Try declaring the function BitMapToRegion as:

	pascal OSErr BitMapToRegion(RgnHandle region, BitMap *bMap)
	    = 0xA8D7; 

and then just say:

	BitMapToRegion(theRgn, theMap);

Hope this helps.

Chris Wysocki
wysocki@husc9.harvard.edu