Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Archive » net.micro.mac » Toolbox action procedures and C
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Toolbox action procedures and C [message #156008] Thu, 17 October 1985 22:33
gijs is currently offline  gijs
Messages: 12
Registered: May 2013
Karma: 0
Junior Member
Article-I.D.: ark.563
Posted: Thu Oct 17 22:33:11 1985
Date-Received: Mon, 21-Oct-85 05:24:08 EDT
Organization: VU Informatica, Amsterdam
Lines: 62

(rn crashed. This is a follow-up to some article)

Action procedures or functions are called from toolbox trap code.
The toolbox has been coded with Lisa Pascal in mind. So it uses
the Lisa Pascal procedure/function calling sequence:
	Reserve space on stack for function result (not done for proc)
	Push parameters
	JSR	(Push return address)
The procedure or function saves the return address, removes parameters
and pushes back the return address before returning.

The calling sequence for C functions is different. Consular C - as an
example - expects its first 7 arguments in D0 - D6. Remaining arguments
are pushed on the stack (in reverse order). The function result is in
A0 if pointer and in D0 otherwise.
The solution is to call your C action function from an assembly routine
that converts calling sequences. As an example (again MacC) a piece 
of code for a scroll control action procedure.



DoScrollAction()
/*
	Convert Pascal to C calling sequence and jump to
	ScrollAction
 */
{
#asm
	MOVE.L	(SP)+,A0	;Save return address
	MOVE.W	(SP)+,D1	;partCode
	EXT.L	D1		;MacC int's are 32 bit
	MOVE.L	(SP)+,D0	;myControl
	MOVE.L	A0,-(SP)	;Return address back on stack
	JMP	ScrollAction
#endasm
}


ScrollAction( myControl, partCode )
ControlHandle myControl;
int partCode;
{
	int value, max, min, page, startCount;
	
	startCount = TickCount();
	
	value = GetCtlValue( myControl );
	max = GetCtlMax( myControl );
	min = GetCtlMin( myControl );
	...
	
Literature:
	- IM chapter on Programming applications in Assembly Language
	- Your C compiler's manual
	
Gijs Mos
Dept. of Biology
Vrije Universiteit
Amsterdam
{seismo,decvax,philabs}!mcvax!vu44!gijs
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Apple suing people, protection of ideas
Next Topic: Re: DRI agrees to change GEM ; why??
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Nov 24 06:22:03 EST 2024

Total time taken to generate the page: 0.01621 seconds